Skip to content
This repository was archived by the owner on Dec 8, 2020. It is now read-only.

RLS is not linting properly #310

Open
dhicksNTIA opened this issue Jun 27, 2017 · 13 comments
Open

RLS is not linting properly #310

dhicksNTIA opened this issue Jun 27, 2017 · 13 comments

Comments

@dhicksNTIA
Copy link

dhicksNTIA commented Jun 27, 2017

Version of VSCode: 1.13.1
Version of the extension: 0.4.2
OS: Linux Mint 18

Description:
RLS is not linting like it used to. Consider the following image:
image
Before, RLS would red underline that bad return value, now it does nothing. Was this change intentional?

Output of the "Rust logging" channel:

DEBUG: Rustup: updateToolchains: this.toolchains=[{"channel":"stable","host":"x86_64-unknown-linux-gnu","isDefault":false},{"channel":"nightly","host":"x86_64-unknown-linux-gnu","isDefault":true}]
DEBUG: activate: processPossibleSetButMissingUserToolchain: toolchainKind=toolchain
DEBUG: activate: processPossibleSetButMissingUserToolchain: user toolchain is installed
DEBUG: Rustup: updateComponents(nightly-x86_64-unknown-linux-gnu): components=["cargo-x86_64-unknown-linux-gnu (default)","rls-x86_64-unknown-linux-gnu (installed)","rust-analysis-x86_64-unknown-linux-gnu (installed)","rust-docs-x86_64-unknown-linux-gnu (default)","rust-src (installed)","rust-std-aarch64-apple-ios","rust-std-aarch64-linux-android","rust-std-aarch64-unknown-fuchsia","rust-std-aarch64-unknown-linux-gnu","rust-std-arm-linux-androideabi","rust-std-arm-unknown-linux-gnueabi","rust-std-arm-unknown-linux-gnueabihf","rust-std-arm-unknown-linux-musleabi","rust-std-arm-unknown-linux-musleabihf","rust-std-armv7-apple-ios","rust-std-armv7-linux-androideabi","rust-std-armv7-unknown-linux-gnueabihf","rust-std-armv7-unknown-linux-musleabihf","rust-std-armv7s-apple-ios","rust-std-asmjs-unknown-emscripten","rust-std-i386-apple-ios","rust-std-i586-pc-windows-msvc","rust-std-i586-unknown-linux-gnu","rust-std-i686-apple-darwin","rust-std-i686-linux-android","rust-std-i686-pc-windows-gnu","rust-std-i686-pc-windows-msvc","rust-std-i686-unknown-freebsd","rust-std-i686-unknown-linux-gnu","rust-std-i686-unknown-linux-musl","rust-std-mips-unknown-linux-gnu","rust-std-mips-unknown-linux-musl","rust-std-mips64-unknown-linux-gnuabi64","rust-std-mips64el-unknown-linux-gnuabi64","rust-std-mipsel-unknown-linux-gnu","rust-std-mipsel-unknown-linux-musl","rust-std-powerpc-unknown-linux-gnu","rust-std-powerpc64-unknown-linux-gnu","rust-std-powerpc64le-unknown-linux-gnu","rust-std-s390x-unknown-linux-gnu","rust-std-sparc64-unknown-linux-gnu","rust-std-wasm32-unknown-emscripten","rust-std-x86_64-apple-darwin","rust-std-x86_64-apple-ios","rust-std-x86_64-linux-android","rust-std-x86_64-pc-windows-gnu","rust-std-x86_64-pc-windows-msvc","rust-std-x86_64-rumprun-netbsd","rust-std-x86_64-unknown-freebsd","rust-std-x86_64-unknown-fuchsia","rust-std-x86_64-unknown-linux-gnu (default)","rust-std-x86_64-unknown-linux-musl","rust-std-x86_64-unknown-netbsd","rustc-x86_64-unknown-linux-gnu (default)",""]
DEBUG: RlsMode: start: enter
DEBUG: RlsMode: start: User decided to use rustfmt
DEBUG: RlsMode: start: rlsPath=/home/dhicks/.cargo/bin/cargo 
DEBUG: RlsMode: start: env={"RUST_SRC_PATH":"/home/dhicks/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src"} 
DEBUG: RlsMode: start: args=["+nightly","run","--manifest-path","/home/dhicks/Documents/rls/Cargo.toml","--release"] 
DEBUG: RlsMode: start: revealOutputChannelOn=3 
DEBUG: RlsMode: start: Language Client Manager: start
DEBUG: RlsMode: start: Language Client Manager: stop
DEBUG: RlsMode: start: Language Client Manager: start
DEBUG: RlsMode: start: Language Client Manager: stop
DEBUG: RlsMode: start: Language Client Manager: start

Output of the "Rust logging" channel:

    Finished release [optimized] target(s) in 0.0 secs
     Running `/home/dhicks/Documents/rls/target/release/rls`
{"message":"mismatched types","code":{"code":"E0308","explanation":"\nThis error occurs when the compiler was unable to infer the concrete type of a\nvariable. It can occur for several cases, the most common of which is a\nmismatch in the expected type that the compiler inferred for a variable's\ninitializing expression, and the actual type explicitly assigned to the\nvariable.\n\nFor example:\n\n```compile_fail,E0308\nlet x: i32 = \"I am not a number!\";\n//     ~~~   ~~~~~~~~~~~~~~~~~~~~\n//      |             |\n//      |    initializing expression;\n//      |    compiler infers type `&str`\n//      |\n//    type `i32` assigned to variable `x`\n```\n"},"level":"error","spans":[{"file_name":"src/lib.rs","byte_start":67,"byte_end":71,"line_start":5,"line_end":5,"column_start":5,"column_end":9,"is_primary":true,"text":[{"text":"    16.3","highlight_start":5,"highlight_end":9}],"label":"expected i32, found floating-point variable","suggested_replacement":null,"expansion":null}],"children":[{"message":"expected type `i32`\n   found type `{float}`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":null}
{"message":"expected type `i32`\n   found type `{float}`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":null}
{"message":"aborting due to previous error(s)","code":null,"level":"error","spans":[],"children":[],"rendered":null}
@KalitaAlexey
Copy link
Member

I think the reason is the same as for #307

@dhicksNTIA
Copy link
Author

dhicksNTIA commented Jun 27, 2017

@KalitaAlexey that is what I thought too, but unlike those issues, my RLS doesn't crash. In that first "message" JSON I can see where it is throwing the error, but maybe VSCODE isn't translating correctly?

@KalitaAlexey
Copy link
Member

@dhicksNTIA,
I see that it has the same {"message"...} which shouldn't be a case.

@DirtGrubDylan
Copy link

@KalitaAlexey
Okay, so after the new RLS update (still have to compile from source, instead of using the rustup version), the linting is still not highlighting warnings or errors.

image

here are the outputs of "Rust Language Server":

{"message":"expected one of `.`, `;`, `?`, or an operator, found `Ok`","code":null,"level":"error","spans":[{"file_name":"src/propagation/diffraction/mod.rs","byte_start":96019,"byte_end":96019,"line_start":99,"line_end":99,"column_start":81,"column_end":81,"is_primary":false,"text":[{"text":"        double_knife_edge::double_knife_edge_attenuation(distance_m, parameters)","highlight_start":81,"highlight_end":81}],"label":"expected one of `.`, `;`, `?`, or an operator here","suggested_replacement":null,"expansion":null},{"file_name":"src/propagation/diffraction/mod.rs","byte_start":96025,"byte_end":96027,"line_start":101,"line_end":101,"column_start":5,"column_end":7,"is_primary":true,"text":[{"text":"    Ok((1.0 - weighting_factor) * double_knife_edge_attenuation +","highlight_start":5,"highlight_end":7}],"label":"unexpected token","suggested_replacement":null,"expansion":null}],"children":[],"rendered":null}
{"message":"aborting due to previous error(s)","code":null,"level":"error","spans":[],"children":[],"rendered":null}

@KalitaAlexey
Copy link
Member

I'm working on #289.
After I've finished it, I'll take a look at the issue.

@DirtGrubDylan
Copy link

@KalitaAlexey If you want, I can take a stab at it. I am not familiar with the source, but is there a place I should start?

@KalitaAlexey
Copy link
Member

KalitaAlexey commented Jul 4, 2017

@DirtGrubDylan I would be glad if you helped.

  • Download the source
  • To src/components/language_client/manager.ts:
    • Add to the beginning the line import { Trace } from 'vscode-jsonrpc';
    • Add the line this.languageClient.trace = Trace.Verbose; after the line this.languageClient = this.languageClientCreator.create(); (31 line)
  • Run the extension from source. Read about it
  • Open the "Rust Language Server" output channel
  • Paste your output here

You can analyze it yourself.
My lib.rs is:

fn main() {
    A.af
}

My output is:

[Trace - 8:45:19 AM] Received notification 'rustDocument/diagnosticsBegin'.
No parameters provided.


[Trace - 8:45:19 AM] Received notification 'rustDocument/diagnosticsBegin'.
No parameters provided.


{"message":"cannot find value `A` in this scope","code":{"code":"E0425","explanation":"\nAn unresolved name was used.\n\nErroneous code examples:\n\n```compile_fail,E0425\nsomething_that_doesnt_exist::foo;\n// error: unresolved name `something_that_doesnt_exist::foo`\n\n// or:\n\ntrait Foo {\n    fn bar() {\n        Self; // error: unresolved name `Self`\n    }\n}\n\n// or:\n\nlet x = unknown_variable;  // error: unresolved name `unknown_variable`\n```\n\nPlease verify that the name wasn't misspelled and ensure that the\nidentifier being referred to is valid for the given situation. Example:\n\n```\nenum something_that_does_exist {\n    Foo,\n}\n```\n\nOr:\n\n```\nmod something_that_does_exist {\n    pub static foo : i32 = 0i32;\n}\n\nsomething_that_does_exist::foo; // ok!\n```\n\nOr:\n\n```\nlet unknown_variable = 12u32;\nlet x = unknown_variable; // ok!\n```\n\nIf the item is not defined in the current module, it must be imported using a\n`use` statement, like so:\n\n```ignore\nuse foo::bar;\nbar();\n```\n\nIf the item you are importing is not defined in some super-module of the\ncurrent module, then it must also be declared as public (e.g., `pub fn`).\n"},"level":"error","spans":[{"file_name":"src\\lib.rs","byte_start":16,"byte_end":17,"line_start":2,"line_end":2,"column_start":5,"column_end":6,"is_primary":true,"text":[{"text":"    A.af","highlight_start":5,"highlight_end":6}],"label":"not found in this scope","suggested_replacement":null,"expansion":null}],"children":[],"rendered":null}
[Trace - 8:45:19 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///C:/Projects/Rust/a%20a/src/lib.rs",
    "diagnostics": [
        {
            "range": {
                "start": {
                    "line": 1,
                    "character": 4
                },
                "end": {
                    "line": 1,
                    "character": 5
                },
                "label": "not found in this scope"
            },
            "secondaryRanges": [],
            "severity": 1,
            "code": "E0425",
            "source": "rustc",
            "message": "cannot find value `A` in this scope\nnot found in this scope"
        }
    ]
}


[Trace - 8:45:19 AM] Received notification 'rustDocument/diagnosticsEnd'.
No parameters provided.


[Trace - 8:45:19 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///C:/Projects/Rust/a%20a/src/lib.rs",
    "diagnostics": [
        {
            "range": {
                "start": {
                    "line": 1,
                    "character": 4
                },
                "end": {
                    "line": 1,
                    "character": 5
                },
                "label": "not found in this scope"
            },
            "secondaryRanges": [],
            "severity": 1,
            "code": "E0425",
            "source": "rustc",
            "message": "cannot find value `A` in this scope\nnot found in this scope"
        }
    ]
}


[Trace - 8:45:19 AM] Received notification 'rustDocument/diagnosticsEnd'.
No parameters provided.


I hope that's clear enough.
Feel free to ask questions.

@DirtGrubDylan
Copy link

@KalitaAlexey So after playing around with the debugger this morning. I found that my bug is not with the linter. It is with the watcher.

Using your lib.rs from above, I also get:

[Trace - 8:16:23 AM] Received notification 'rustDocument/diagnosticsBegin'.
No parameters provided.


[Trace - 8:16:23 AM] Sending request 'textDocument/codeAction - (1)'.
Params: {
    "textDocument": {
        "uri": "file:///home/dhicks/Documents/rls_test/src/lib.rs"
    },
    "range": {
        "start": {
            "line": 2,
            "character": 1
        },
        "end": {
            "line": 2,
            "character": 1
        }
    },
    "context": {
        "diagnostics": []
    }
}


[Trace - 8:16:23 AM] Received request 'client/registerCapability - (1)'.
Params: {
    "registrations": [
        {
            "id": "rls-watch",
            "method": "workspace/didChangeWatchedFiles",
            "registerOptions": {
                "watchers": [
                    {
                        "globPattern": "/home/dhicks/Documents/rls_test/Cargo{.toml,.lock}"
                    }
                ]
            }
        }
    ]
}


[Trace - 8:16:23 AM] Sending response 'client/registerCapability - (1)'. Processing request took 0ms
[Trace - 8:16:23 AM] Received response 'textDocument/codeAction - (1)' in 1ms. Request failed: Invalid request (-32600).
[Error - 8:16:23 AM] Request textDocument/codeAction failed.
  Message: Invalid request
  Code: -32600 
{"message":"cannot find value `A` in this scope","code":{"code":"E0425","explanation":"\nAn unresolved name was used.\n\nErroneous code examples:\n\n```compile_fail,E0425\nsomething_that_doesnt_exist::foo;\n// error: unresolved name `something_that_doesnt_exist::foo`\n\n// or:\n\ntrait Foo {\n    fn bar() {\n        Self; // error: unresolved name `Self`\n    }\n}\n\n// or:\n\nlet x = unknown_variable;  // error: unresolved name `unknown_variable`\n```\n\nPlease verify that the name wasn't misspelled and ensure that the\nidentifier being referred to is valid for the given situation. Example:\n\n```\nenum something_that_does_exist {\n    Foo,\n}\n```\n\nOr:\n\n```\nmod something_that_does_exist {\n    pub static foo : i32 = 0i32;\n}\n\nsomething_that_does_exist::foo; // ok!\n```\n\nOr:\n\n```\nlet unknown_variable = 12u32;\nlet x = unknown_variable; // ok!\n```\n\nIf the item is not defined in the current module, it must be imported using a\n`use` statement, like so:\n\n```\n# mod foo { pub fn bar() {} }\n# fn main() {\nuse foo::bar;\nbar();\n# }\n```\n\nIf the item you are importing is not defined in some super-module of the\ncurrent module, then it must also be declared as public (e.g., `pub fn`).\n"},"level":"error","spans":[{"file_name":"src/lib.rs","byte_start":16,"byte_end":17,"line_start":2,"line_end":2,"column_start":5,"column_end":6,"is_primary":true,"text":[{"text":"    A.af","highlight_start":5,"highlight_end":6}],"label":"not found in this scope","suggested_replacement":null,"expansion":null}],"children":[],"rendered":null}
{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":null}
[Trace - 8:16:24 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///home/dhicks/Documents/rls_test/src/lib.rs",
    "diagnostics": [
        {
            "range": {
                "start": {
                    "line": 1,
                    "character": 4
                },
                "end": {
                    "line": 1,
                    "character": 5
                }
            },
            "severity": 1,
            "code": "E0425",
            "source": "rustc",
            "message": "cannot find value `A` in this scope"
        }
    ]
}


[Trace - 8:16:24 AM] Received notification 'rustDocument/diagnosticsEnd'.
No parameters provided.

but, if I add an empty main.rs to my src and change my Cargo.toml from

[package]
name = "rls_test"
version = "0.1.0"
authors = ["Dylan Hicks <[email protected]>"]

[dependencies]

to

[package]
name = "RLS Test"
version = "0.1.0"
authors = ["Dylan Hicks <[email protected]>"]

[lib]
name = "testrls"
path = "src/lib.rs"
doctest = false
crate-type = ["rlib", "dylib"]

[[bin]]
name = "rlsrun"
path = "src/main.rs"

[dependencies]

then the linter quits working, and I get:

[Trace - 8:22:39 AM] Received notification 'rustDocument/diagnosticsBegin'.
No parameters provided.


[Trace - 8:22:39 AM] Sending request 'textDocument/codeAction - (1)'.
Params: {
    "textDocument": {
        "uri": "file:///home/dhicks/Documents/rls_test/src/lib.rs"
    },
    "range": {
        "start": {
            "line": 0,
            "character": 0
        },
        "end": {
            "line": 0,
            "character": 2
        }
    },
    "context": {
        "diagnostics": []
    }
}


[Trace - 8:22:39 AM] Received request 'client/registerCapability - (1)'.
Params: {
    "registrations": [
        {
            "id": "rls-watch",
            "method": "workspace/didChangeWatchedFiles",
            "registerOptions": {
                "watchers": [
                    {
                        "globPattern": "/home/dhicks/Documents/rls_test/Cargo{.toml,.lock}"
                    }
                ]
            }
        }
    ]
}


[Trace - 8:22:39 AM] Sending response 'client/registerCapability - (1)'. Processing request took 0ms
[Trace - 8:22:39 AM] Received response 'textDocument/codeAction - (1)' in 1ms. Request failed: Invalid request (-32600).
[Error - 8:22:39 AM] Request textDocument/codeAction failed.
  Message: Invalid request
  Code: -32600 
{"message":"cannot find value `A` in this scope","code":{"code":"E0425","explanation":"\nAn unresolved name was used.\n\nErroneous code examples:\n\n```compile_fail,E0425\nsomething_that_doesnt_exist::foo;\n// error: unresolved name `something_that_doesnt_exist::foo`\n\n// or:\n\ntrait Foo {\n    fn bar() {\n        Self; // error: unresolved name `Self`\n    }\n}\n\n// or:\n\nlet x = unknown_variable;  // error: unresolved name `unknown_variable`\n```\n\nPlease verify that the name wasn't misspelled and ensure that the\nidentifier being referred to is valid for the given situation. Example:\n\n```\nenum something_that_does_exist {\n    Foo,\n}\n```\n\nOr:\n\n```\nmod something_that_does_exist {\n    pub static foo : i32 = 0i32;\n}\n\nsomething_that_does_exist::foo; // ok!\n```\n\nOr:\n\n```\nlet unknown_variable = 12u32;\nlet x = unknown_variable; // ok!\n```\n\nIf the item is not defined in the current module, it must be imported using a\n`use` statement, like so:\n\n```\n# mod foo { pub fn bar() {} }\n# fn main() {\nuse foo::bar;\nbar();\n# }\n```\n\nIf the item you are importing is not defined in some super-module of the\ncurrent module, then it must also be declared as public (e.g., `pub fn`).\n"},"level":"error","spans":[{"file_name":"src/lib.rs","byte_start":16,"byte_end":17,"line_start":2,"line_end":2,"column_start":5,"column_end":6,"is_primary":true,"text":[{"text":"    A.af","highlight_start":5,"highlight_end":6}],"label":"not found in this scope","suggested_replacement":null,"expansion":null}],"children":[],"rendered":null}
{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":null}
[Trace - 8:22:39 AM] Received notification 'rustDocument/diagnosticsEnd'.
No parameters provided.


[Trace - 8:23:00 AM] Sending request 'textDocument/codeAction - (2)'.
Params: {
    "textDocument": {
        "uri": "file:///home/dhicks/Documents/rls_test/src/lib.rs"
    },
    "range": {
        "start": {
            "line": 0,
            "character": 0
        },
        "end": {
            "line": 0,
            "character": 2
        }
    },
    "context": {
        "diagnostics": []
    }
}


[Trace - 8:23:00 AM] Received response 'textDocument/codeAction - (2)' in 3ms.
Result: []

@DirtGrubDylan
Copy link

It appears that having both a lib.rs and either a main.rs or defining a [[bin]] in the Cargo.toml breaks the linter.

I have tried just having a lib.rs and defining a [[bin]] in the Cargo.toml, and it broke.
I have tried just having a lib.rs and a main.rs, without defining a [[bin]], and it broke.
I have tried having a lib.rs and a main.rs, with defining a [[bin]], and it broke.
I have tried just having a lib.rs, and it works.

@KalitaAlexey
Copy link
Member

@nrc,
Are you aware of that?
I didn't touch RLS in a long time.

@watzon
Copy link

watzon commented Aug 11, 2017

It looks like having 2 main functions could be causing the issue. I had main.rs as well as another file both of which with fn main() {} and it stopped working. It started working again as soon as I remove the second main and restarted the editor

@KalitaAlexey
Copy link
Member

@watzon,
What if you didn't remove the second main, but restarted the editor?
Would it start working?

@daltonhildreth
Copy link

I had this issue when opening a folder above multiple rust folders (thus having multiple main functions). It was fixed when I did what @watzon suggested.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants