Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing field range #13503

Open
max397574 opened this issue Oct 28, 2022 · 3 comments
Open

missing field range #13503

max397574 opened this issue Oct 28, 2022 · 3 comments
Labels
A-lsp LSP conformance issues and missing features C-support Category: support questions

Comments

@max397574
Copy link

I'm getting this return value from a code action request:

{ {
    error = {
      code = -32602,
      message = "Failed to deserialize textDocument/codeAction: missing field `range`; {\"range\":{\"start\":{\"line\":11,\"character\":4},\"end\":{\"line\":11,\"character\":4}},\"context\":{\"diagnostics\":[{\"end_col\":61,\"severity\":1,\"bufnr\":1,\"end_lnum\":11,\"code\":\"E0381\",\"col\":4,\"namespace\":33,\"lnum\":11,\"message\":\"used binding `options` isn't initialized\\n`options` used here but it isn't initialized\",\"user_data\":{\"lsp\":{\"codeDescription\":{\"href\":\"https://doc.rust-lang.org/error-index.html#E0381\"},\"relatedInformation\":[{\"message\":\"binding declared here but left uninitialized\",\"location\":{\"uri\":\"file:///Users/max/programming/rust/algorithms/src/fuzzy.rs\",\"range\":{\"start\":{\"line\":10,\"character\":8},\"end\":{\"line\":10,\"character\":15}}}},{\"message\":\"consider assigning a value: ` = vec![]`\",\"location\":{\"uri\":\"file:///Users/max/programming/rust/algorithms/src/fuzzy.rs\",\"range\":{\"start\":{\"line\":10,\"character\":25},\"end\":{\"line\":10,\"character\":25}}}}],\"code\":\"E0381\"}},\"source\":\"rustc\"}]},\"textDocument\":{\"uri\":\"file:///Users/max/programming/rust/algorithms/src/fuzzy.rs\"}}",
      <metatable> = {
        __tostring = <function 1>
      }
    }
  } }

even though there is a range field

@lnicola lnicola added the A-lsp LSP conformance issues and missing features label Oct 28, 2022
@lnicola
Copy link
Member

lnicola commented Oct 28, 2022

Which client is that from? Does it reproduce reliably?

The request looks fine as far as I can tell..

@max397574
Copy link
Author

it's from neovim
I'll try to make sth to reproduce it

@max397574
Copy link
Author

I'm not sure if some things could be removed (not very good with rust yet)
The error:

{ {
    error = {
      code = -32602,
      message = "Failed to deserialize textDocument/codeAction: missing field `range`; {\"textDocument\":{\"uri\":\"file:///Users/max/programming/rust/algorithms/src/fuzzy.rs\"},\"context\":{\"diagnostics\":[{\"end_col\":33,\"code\":\"E0381\",\"message\":\"used binding `options` isn't initialized\\n`options` used here but it isn't initialized\",\"namespace\":33,\"bufnr\":1,\"severity\":1,\"lnum\":16,\"col\":19,\"end_lnum\":16,\"user_data\":{\"lsp\":{\"codeDescription\":{\"href\":\"https://doc.rust-lang.org/error-index.html#E0381\"},\"relatedInformation\":[{\"location\":{\"range\":{\"start\":{\"line\":15,\"character\":8},\"end\":{\"line\":15,\"character\":15}},\"uri\":\"file:///Users/max/programming/rust/algorithms/src/fuzzy.rs\"},\"message\":\"binding declared here but left uninitialized\"},{\"location\":{\"range\":{\"start\":{\"line\":15,\"character\":25},\"end\":{\"line\":15,\"character\":25}},\"uri\":\"file:///Users/max/programming/rust/algorithms/src/fuzzy.rs\"},\"message\":\"consider assigning a value: ` = vec![]`\"}],\"code\":\"E0381\"}},\"source\":\"rustc\"}]},\"range\":{\"start\":{\"line\":16,\"character\":24},\"end\":{\"line\":16,\"character\":24}}}",
      <metatable> = {
        __tostring = <function 1>
      }
    }
  } }

src/main.rs

mod fuzzy;

fn main() {
    let x = "kitten";
    let y= "sitting";
    println!(
        "The levensheit distance between {} and {} is {}",
        x,
        y,
        fuzzy::levenshtein_distance_recursive(String::from("kitten"), String::from("sitting"))
    );
}

src/fuzzy.rs

// https://en.wikipedia.org/wiki/Levenshtein_distance
pub fn levenshtein_distance_recursive(a: String, b: String) -> u32 {
    if a.is_empty() {
        return b.len().try_into().unwrap();
    } else if b.is_empty() {
        return a.len().try_into().unwrap();
    }
    if a[0..1] == b[0..1] {
        return levenshtein_distance_recursive(a[1..].to_string(), b[1..].to_string());
    }
    // let options: Vec<u32> = vec![
    //     levenshtein_distance_recursive(a[1..].to_string(), b.clone()),
    //     levenshtein_distance_recursive(a.clone(), b[1..].to_string()),
    //     levenshtein_distance_recursive(a[1..].to_string(), b[1..].to_string()),
    // ];
    let options: Vec<u32>;
    let smallest = options.iter().min(); // cursor is on this line on `options`
    match smallest {
        None => {
            panic!("Some error occured")
        }
        Some(i) => 1 + *i,
    }
}

@Veykril Veykril added the C-support Category: support questions label Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lsp LSP conformance issues and missing features C-support Category: support questions
Projects
None yet
Development

No branches or pull requests

3 participants