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

Rust editor doesn't show errors #162

Closed
ctron opened this issue Oct 26, 2018 · 42 comments
Closed

Rust editor doesn't show errors #162

ctron opened this issue Oct 26, 2018 · 42 comments

Comments

@ctron
Copy link

ctron commented Oct 26, 2018

I have the following rust code in the editor:

fn main() {
    let a = "Foo";
    println!("Hello, world!" + a);
}

However, trying to run this from the IDE I do get:

   Compiling new_rust_project v0.1.0 (/home/jreimann/Development/workspace-rust/new_rust_project)
error: format argument must be a string literal
 --> src/main.rs:3:14
  |
3 |     println!("Hello, world!" + a);
  |              ^^^^^^^^^^^^^^^^^^^
help: you might be missing a string literal to format with
  |
3 |     println!("{}", "Hello, world!" + a);
  |              ^^^^^

error: aborting due to previous error

error: Could not compile `new_rust_project`.

To learn more, run the command again with --verbose.

Also see:

image

My expectations would be:

  • The editor shows the same errors, at least when I save the file, or after it got compiled
  • Locations (file + line number) in the log output can be clicked in, to open the file in the IDE
  • I see some error markers in the project explorer
@Boereck
Copy link
Contributor

Boereck commented Oct 26, 2018

Hi!
Actually, errors should be shown directly in the file, as decorators on the file in the Project Explorer and in the Problems view. If they do not show up, there might be a problem in the communication to the RLS. In my experience sometimes the RLS hangs and Eclipse has to be restarted. If this does not help, please have a look in the Corrosion properties, if you get an error message, e.g. that the RLS cannot be found.

@ctron
Copy link
Author

ctron commented Oct 29, 2018

Restarting didn't help. The properties page also looks ok. However on startup if get an error notification of:

Cargo failed: Error compiling dependent crate

@Boereck
Copy link
Contributor

Boereck commented Oct 29, 2018

Interesting! I don't know how the RLS behaves when one of the dependent crate does not compile. Can you start the compilation from a run config to see if the error occurs then as well and which crate fails to compile with which error message? Thanks!

@ctron
Copy link
Author

ctron commented Oct 30, 2018

Well that is the output of the initial comment.

@Boereck
Copy link
Contributor

Boereck commented Oct 30, 2018

This is strange, can you fix the program, e.g. writing println!("Hello, world! {}", a); and run the build again? I guess you didn't manually add a dependency to your Cargo.toml file yet. My hunch is, that your settings with regard to the Rust standard lib is still messed up.

@norru
Copy link
Contributor

norru commented Oct 30, 2018

RLS stops working when it can't compile an upstream crate - this has been reported.

rust-lang/rls#1078
#141

You can try to run

rls --cli

from the root of your crate and at least see if there is a workaround for that specific crate.

@ctron
Copy link
Author

ctron commented Nov 5, 2018

So I did check the settings you mentioned in #160, and I did remove the RPM containing rust:

[jreimann@jreimann ~]$ rpm -qa | grep rust
p11-kit-trust-0.23.5-3.el7.x86_64

It seems to pick up the correct binary as well:

➜  new_rust_project_2 which rls
~/.cargo/bin/rls

When I do start rls as you mentioned, I get the following output:

rls output

➜  new_rust_project_2 rls --cli
Initializing (look for `progress[done:true]` message)...
> 1: InitializeResult {
    capabilities: ServerCapabilities {
        text_document_sync: Some(
            Kind(
                Incremental
            )
        ),
        hover_provider: Some(
            true
        ),
        completion_provider: Some(
            CompletionOptions {
                resolve_provider: Some(
                    true
                ),
                trigger_characters: Some(
                    [
                        ".",
                        ":"
                    ]
                )
            }
        ),
        signature_help_provider: None,
        definition_provider: Some(
            true
        ),
        type_definition_provider: None,
        implementation_provider: Some(
            Simple(
                true
            )
        ),
        references_provider: Some(
            true
        ),
        document_highlight_provider: Some(
            true
        ),
        document_symbol_provider: Some(
            true
        ),
        workspace_symbol_provider: Some(
            true
        ),
        code_action_provider: Some(
            true
        ),
        code_lens_provider: Some(
            CodeLensOptions {
                resolve_provider: Some(
                    false
                )
            }
        ),
        document_formatting_provider: Some(
            true
        ),
        document_range_formatting_provider: Some(
            false
        ),
        document_on_type_formatting_provider: None,
        rename_provider: Some(
            true
        ),
        color_provider: None,
        execute_command_provider: Some(
            ExecuteCommandOptions {
                commands: [
                    "rls.applySuggestion-26520",
                    "rls.deglobImports-26520"
                ]
            }
        )
    }
}
{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_1","title":"Building"}}
{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_1","message":"new_rust_project_2","title":"Building"}}
{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_1","message":"new_rust_project_2","title":"Building"}}
{"jsonrpc":"2.0","method":"window/progress","params":{"done":true,"id":"progress_1","title":"Building"}}
{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_0","title":"Indexing"}}
{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"code":"","message":"format argument must be a string literal\n\nhelp: you might be missing a string literal to format with: `\"{}\", `","range":{"end":{"character":32,"line":2},"start":{"character":13,"line":2}},"severity":1,"source":"rustc"}],"uri":"file:///home/jreimann/Development/workspace-rust/new_rust_project_2/src/main.rs"}}
{"jsonrpc":"2.0","method":"window/progress","params":{"done":true,"id":"progress_0","title":"Indexing"}}

@norru
Copy link
Contributor

norru commented Nov 6, 2018

Looks correct!

If you load the project in the IDE do you get the error in the problem list (and see the squiggles in the editor)?

Do you still get "Cargo failed: Error compiling dependent crate"?

If yes, can you try and run cargo clean from the root of your project, with the IDE not running? (will get rid of the cache, including potentially corrupted entries).

@ctron
Copy link
Author

ctron commented Nov 7, 2018

So, when I start the Eclipse instance I get the following error box:

image

The editor part shows no errors:

image

I then shut down the IDE, ran cargo clean in the directory of the project (which didn't give any output). Started up the IDE again, and ran into the same behavior.

@Boereck
Copy link
Contributor

Boereck commented Nov 7, 2018

Hey @ctron can you provide a screenshot of your Rust properties page? Thanks! If the RLS from the command line yealds a correct result, but when invoked from command line it does no, I suspect a config error. Maybe on the initial start the system installation was picked up and now that you use the rustup installed version points to a wrong directory.

@ctron
Copy link
Author

ctron commented Nov 7, 2018

Sure, here it is:

image

@Boereck
Copy link
Contributor

Boereck commented Nov 7, 2018

Hey @ctron, thanks for providing the info. My guess is that the sysroot directory detection failed somehow. The default value set in the "Other installation" text box does not look correct. Can you select the "Other installation" radio button and set the 'sysroot' field to the correct location? The sysroot would be something like ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu. You may have to restart Eclipse, I am not sure under which circumstances the language server gets restarted. If this works we would have to diagnose how it came to the wrong sysroot detection.

I don't know if the error message on startup produces an entry in the workspace .metadata/.log file. If it does, it would also be interesting to see those.

@ctron
Copy link
Author

ctron commented Nov 8, 2018

Thanks for your help!

So I did check the .metadata/.log file, it does contain a bunch of messages, but nothing which looks anything close to the RLS message.

I also changed the settings to:

image

By:

  • Switching to "other"
  • Entering the new path (which seems to exist in the file system)
  • Pressing "Apply and Close"
  • Switching to "Use Rustup"
  • Pressing "Apply and Close"
  • Restart the Eclipse IDE

But then the same error comes up after the restart.

@Boereck
Copy link
Contributor

Boereck commented Nov 8, 2018

Sorry, there was a misunderstanding. Please do not switch back to "Use Rustup" in your settings. This is just for the moment to find out if the manual setting works. If it works, we can try to find out why the automatic detection does not work.

@ctron
Copy link
Author

ctron commented Nov 8, 2018

Ok, sorry. Let me try again.

… still the same with the following settings:

image

@Boereck
Copy link
Contributor

Boereck commented Nov 8, 2018

Thanks @ctron, so it does not seem to be a sysroot configuration error. Can you go into the preferences and go to page Language Servers > Logs and enable "Log to File" or "Log to Console" for the "org.eclipse.corrosion.RLS" server? Then restart Eclipse again. It would be interesting to see the first messages being exchanged to maybe get more detailed information on the error.

It is baffling that the RLS works from command line, but not when invoked from Eclipse.

@ctron
Copy link
Author

ctron commented Nov 9, 2018

The output is here:

RLS log output
LSP4E to org.eclipse.corrosion.rls:Content-Length: 802


LSP4E to org.eclipse.corrosion.rls:{"jsonrpc":"2.0","id":"1","method":"initialize","params":{"processId":9720,"rootPath":"/home/jreimann/Development/workspace-rust/new_rust_project_2/","rootUri":"file:///home/jreimann/Development/workspace-rust/new_rust_project_2/","capabilities":{"workspace":{"applyEdit":true,"symbol":{},"executeCommand":{"dynamicRegistration":true},"workspaceFolders":true},"textDocument":{"synchronization":{"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"completionItem":{"snippetSupport":true}},"hover":{},"signatureHelp":{},"references":{},"documentHighlight":{},"documentSymbol":{},"formatting":{},"rangeFormatting":{},"definition":{},"codeAction":{"codeActionLiteralSupport":{}},"codeLens":{},"documentLink":{},"colorProvider":{},"rename":{}}},"clientName":"Eclipse IDE","trace":"off"}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","id":1,"result":{"capabilities":{"textDocumentSync":2,"hoverProvider":true,"completionProvider":{"resolveProvider":true,"triggerCharacters":[".",":"]},"definitionProvider":true,"implementationProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"workspaceSymbolProvider":true,"codeActionProvider":true,"codeLensProvider":{"resolveProvider":false},"documentFormattingProvider":true,"documentRangeFormattingProvider":false,"renameProvider":true,"executeCommandProvider":{"commands":["rls.applySuggestion-9791","rls.deglobImports-9791"]}}}}
LSP4E to org.eclipse.corrosion.rls:Content-Length: 52


LSP4E to org.eclipse.corrosion.rls:{"jsonrpc":"2.0","method":"initialized","params":{}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_1","title":"Building"}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","method":"window/progress","params":{"done":true,"id":"progress_1","title":"Building"}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_0","title":"Indexing"}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","method":"window/showMessage","params":{"message":"Cargo failed: Error compiling dependent crate","type":1}}
LSP4E to org.eclipse.corrosion.rls:Content-Length: 284


LSP4E to org.eclipse.corrosion.rls:{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///home/jreimann/Development/workspace-rust/new_rust_project_2/src/main.rs","languageId":"rs","version":1,"text":"fn main() {\n    let a \u003d \"Foo\";\n    println!(\"Hello, world!\" + a);\n}"}}}
LSP4E to org.eclipse.corrosion.rls:Content-Length: 175


LSP4E to org.eclipse.corrosion.rls:{"jsonrpc":"2.0","id":"2","method":"textDocument/codeLens","params":{"textDocument":{"uri":"file:///home/jreimann/Development/workspace-rust/new_rust_project_2/src/main.rs"}}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","method":"window/progress","params":{"done":true,"id":"progress_0","title":"Indexing"}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","method":"client/registerCapability","id":1,"params":{"registrations":[{"id":"rls-watch","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"/home/jreimann/Development/workspace-rust/new_rust_project_2//Cargo.lock"},{"globPattern":"/home/jreimann/Development/workspace-rust/new_rust_project_2//target","kind":4},{"globPattern":"/home/jreimann/Development/workspace-rust/new_rust_project_2/Cargo.toml"}]}}]}}
LSP4E to org.eclipse.corrosion.rls:Content-Length: 38


LSP4E to org.eclipse.corrosion.rls:{"jsonrpc":"2.0","id":1,"result":null}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","id":2,"result":[]}
LSP4E to org.eclipse.corrosion.rls:Content-Length: 181


LSP4E to org.eclipse.corrosion.rls:{"jsonrpc":"2.0","id":"3","method":"textDocument/documentSymbol","params":{"textDocument":{"uri":"file:///home/jreimann/Development/workspace-rust/new_rust_project_2/src/main.rs"}}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","id":3,"result":[]}
LSP4E to org.eclipse.corrosion.rls:Content-Length: 220


LSP4E to org.eclipse.corrosion.rls:{"jsonrpc":"2.0","id":"4","method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///home/jreimann/Development/workspace-rust/new_rust_project_2/src/main.rs"},"position":{"line":3,"character":1}}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","id":4,"result":[]}
LSP4E to org.eclipse.corrosion.rls:Content-Length: 220


LSP4E to org.eclipse.corrosion.rls:{"jsonrpc":"2.0","id":"5","method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///home/jreimann/Development/workspace-rust/new_rust_project_2/src/main.rs"},"position":{"line":3,"character":1}}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","id":5,"result":[]}

@Boereck
Copy link
Contributor

Boereck commented Nov 12, 2018

Thanks @ctron! It seems a bit weird that the RLS output log the project dir as new_rust_project_2, but your screenshots show new_rust_project. Did you create a second project in the meantime, or did you rename the project? In some cases the rename refactoring does not rename the underlying folder name which in some cases may cause bugs, because some code assumes project and folder name to match.

If you simply created a second project, then I am again clueless what happens here. Can you maybe also provide the content of your Cargo.toml file? This is a moon shot, I assume you didn't edit this file.

@ctron
Copy link
Author

ctron commented Nov 13, 2018

Yes, I did create a second project for testing. I did not rename it:

image

image

image

Sure, here is the cargo file:

[package]
name = "new_rust_project_2"
version = "0.1.0"
authors = ["Jens Reimann <jreimann@redhat.com>"]

[dependencies]

@Boereck
Copy link
Contributor

Boereck commented Nov 13, 2018

So you don't have dependencies declared, so either RLS has some strange error during startup and this occurres when it tries so build the dependant projects (even though there are none), or something is wrong with the standard lib (which seems less plausible). This is getting hard to diagnose. Maybe you can set the following env variable export RUST_LOG=rls=trace,cargo=trace and start Eclipse from this terminal.
The RLS should then create log files in your project directory, hopefully providing more detailed information which operation actually fails. Thanks a bunch!

@ctron
Copy link
Author

ctron commented Nov 14, 2018

Ok ... now I got something.

The RUST_LOG variable didn't trigger any logs. But … it did start eclipse from the command line for doing that, instead of starting it from the file manager.

Et voilà … now I got the error in the editor. Re-starting again from the file manager, and I do run into the same issue again. So I definitely can re-produce this now.

Unfortunately the error highlighting works, the IDE stalls with a "timeout" exception towards the language server and fails to "index". But that is another issue for another day.

@norru
Copy link
Contributor

norru commented Nov 14, 2018

@ctron @mickaelistria #164 #165

@Boereck
Copy link
Contributor

Boereck commented Nov 21, 2018

@ctron, to come back to the issue: I am puzzled why it works from the command line, but not when started from the file manager. This is more of a workaround than a solution. My imagination can only come up with file permission issues.

If you are interested in finding the root cause, we could try again getting more log data to work on. You could add the RUST_LOG environment variable export to your ~/.bash_profile file. If this works, you should get the compiler log messages as part of the RLS log (enable via Language Servers > Logs again). Thank you again, for all the feedback.

@mickaelistria
Copy link
Contributor

It could be caused by different environment variables maybe.
Can you please diff the proc/<pid>/environ of RLS when it works from CLI vs when it doesn't from File Manager?

@mickaelistria
Copy link
Contributor

Also, can you please diff the log files from RLS/LSP4E when it works vs when it doesn't?

@ctron
Copy link
Author

ctron commented Nov 22, 2018

rust-fails.log
rust-works.log

I couldn't see much from the diff though.

@Boereck
Copy link
Contributor

Boereck commented Nov 22, 2018

@ctron, these logs do not include any rust logs, did you add the RUST_LOG env variable to your ~/.bash_profile and (I forgot to mention this earlier) restart your OS UI session? The diff of environment variables as mentioned by @mickaelistria would also be interesting.

@norru
Copy link
Contributor

norru commented Nov 22, 2018

@ctron You probably can do with running the following from a terminal session on your UI desktop, no restart required.

RUST_LOG=rls=debug /path/to/your/eclipse &

@ctron
Copy link
Author

ctron commented Nov 23, 2018

Well I did try that. Maybe you could try to reproduce my issue on a local machine. In that case you could do all the debugging directly.

Here is what I did:

  • Install Linux (I went with RHEL, CentOS should work the same way, I heard from a colleague that he had the same issues with Fedora)
  • Use Eclipse installer to install the "Comitters" version of Eclipse
  • Install Corrosion
  • Open the file manager (Nautilus, Nemo), navigate to the directory of the eclipse binary, run it by double clicking

@mickaelistria
Copy link
Contributor

@ctron if you take the Rust package from https://ci.eclipse.org/packaging/job/simrel.epp-tycho-build/lastSuccessfulBuild/artifact/org.eclipse.epp.packages/archive/ (bypassing the installer), do you experiment the same issue? I'm trying to sort out whether this can be related to installer vs zip structure.

@ngortheone
Copy link

I have similar problem:
I open popular Rust repo https://github.com/jwilm/alacritty (master)

I see the same popup with message as @ctron
https://user-images.githubusercontent.com/202474/48117317-19f91d80-e269-11e8-95cf-d6e80b594a0c.png

RLS log:

LSP4E to org.eclipse.corrosion.rls:Content-Length: 146

LSP4E to org.eclipse.corrosion.rls:{"jsonrpc":"2.0","method":"textDocument/didClose","params":{"textDocument":{"uri":"file:///Users/ihorantonov/dev/eclipse/alacritty/src/main.rs"}}}
LSP4E to org.eclipse.corrosion.rls:Content-Length: 60


LSP4E to org.eclipse.corrosion.rls:{"jsonrpc":"2.0","id":"5","method":"shutdown","params":null}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","id":5,"result":null}
LSP4E to org.eclipse.corrosion.rls:Content-Length: 763


LSP4E to org.eclipse.corrosion.rls:{"jsonrpc":"2.0","id":"1","method":"initialize","params":{"processId":73716,"rootPath":"/Users/ihorantonov/dev/eclipse/alacritty/","rootUri":"file:///Users/ihorantonov/dev/eclipse/alacritty/","capabilities":{"workspace":{"applyEdit":true,"symbol":{},"executeCommand":{"dynamicRegistration":true},"workspaceFolders":true},"textDocument":{"synchronization":{"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"completionItem":{"snippetSupport":true}},"hover":{},"signatureHelp":{},"references":{},"documentHighlight":{},"documentSymbol":{},"formatting":{},"rangeFormatting":{},"definition":{},"codeAction":{"codeActionLiteralSupport":{}},"codeLens":{},"documentLink":{},"colorProvider":{},"rename":{}}},"clientName":"Eclipse IDE","trace":"off"}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","id":1,"result":{"capabilities":{"textDocumentSync":2,"hoverProvider":true,"completionProvider":{"resolveProvider":true,"triggerCharacters":[".",":"]},"definitionProvider":true,"implementationProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"workspaceSymbolProvider":true,"codeActionProvider":true,"codeLensProvider":{"resolveProvider":false},"documentFormattingProvider":true,"documentRangeFormattingProvider":false,"renameProvider":true,"executeCommandProvider":{"commands":["rls.applySuggestion-73819","rls.deglobImports-73819"]}}}}
LSP4E to org.eclipse.corrosion.rls:Content-Length: 52


LSP4E to org.eclipse.corrosion.rls:{"jsonrpc":"2.0","method":"initialized","params":{}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_1","title":"Building"}}
LSP4E to org.eclipse.corrosion.rls:Content-Length: 10159


LSP4E to org.eclipse.corrosion.rls:{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///Users/ihorantonov/dev/eclipse/alacritty/src/main.rs","languageId":"rs","version":1,"text":"// Copyright 2016 Joe Wilm, The Alacritty Project Contributors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n//\n//! Alacritty - The GPU Enhanced Terminal\n#![cfg_attr(feature \u003d \"cargo-clippy\", deny(clippy, if_not_else, enum_glob_use, wrong_pub_self_convention))]\n#![cfg_attr(feature \u003d \"nightly\", feature(core_intrinsics))]\n#![cfg_attr(all(test, feature \u003d \"bench\"), feature(test))]\n\n// With the default subsystem, \u0027console\u0027, windows creates an additional console\n// window for the program.\n// This is silently ignored on non-windows systems.\n// See https://msdn.microsoft.com/en-us/library/4cc7ya5b.aspx for more details.\n#![windows_subsystem \u003d \"windows\"]\n\n#[macro_use]\nextern crate alacritty;\n\n#[macro_use]\nextern crate log;\n#[cfg(target_os \u003d \"macos\")]\nextern crate dirs;\n\nuse std::error::Error;\nuse std::sync::Arc;\n\n#[cfg(target_os \u003d \"macos\")]\nuse std::env;\n\n#[cfg(not(windows))]\nuse std::os::unix::io::AsRawFd;\n\n#[cfg(windows)]\nextern crate winapi;\n#[cfg(windows)]\nuse winapi::um::wincon::{AttachConsole, FreeConsole, ATTACH_PARENT_PROCESS};\n\nuse alacritty::cli;\nuse alacritty::config::{self, Config};\nuse alacritty::display::Display;\nuse alacritty::event;\nuse alacritty::event_loop::{self, EventLoop, Msg};\n#[cfg(target_os \u003d \"macos\")]\nuse alacritty::locale;\nuse alacritty::logging::{self, LoggerProxy};\nuse alacritty::sync::FairMutex;\nuse alacritty::term::Term;\nuse alacritty::tty::{self, process_should_exit};\nuse alacritty::util::fmt::Red;\n\nfn main() {\n    // When linked with the windows subsystem windows won\u0027t automatically attach\n    // to the console of the parent process, so we do it explicitly. This fails\n    // silently if the parent has no console.\n    #[cfg(windows)]\n    unsafe { AttachConsole(ATTACH_PARENT_PROCESS); }\n\n    // Load command line options\n    let options \u003d cli::Options::load();\n\n    // Initialize the logger as soon as possible as to capture output from other subsystems\n    let logger_proxy \u003d logging::initialize(\u0026options).expect(\"Unable to initialize logger\");\n\n    // Load configuration file\n    let config \u003d load_config(\u0026options).update_dynamic_title(\u0026options);\n\n    // Switch to home directory\n    #[cfg(target_os \u003d \"macos\")]\n    env::set_current_dir(dirs::home_dir().unwrap()).unwrap();\n    // Set locale\n    #[cfg(target_os \u003d \"macos\")]\n    locale::set_locale_environment();\n\n    // Run alacritty\n    if let Err(err) \u003d run(config, \u0026options, logger_proxy) {\n        die!(\"Alacritty encountered an unrecoverable error:\\n\\n\\t{}\\n\", Red(err));\n    }\n}\n\n/// Load configuration\n///\n/// If a configuration file is given as a command line argument we don\u0027t\n/// generate a default file. If an empty configuration file is given, i.e.\n/// /dev/null, we load the compiled-in defaults.)\nfn load_config(options: \u0026cli::Options) -\u003e Config {\n    let config_path \u003d options.config_path()\n        .or_else(Config::installed_config)\n        .unwrap_or_else(|| {\n            Config::write_defaults()\n                .unwrap_or_else(|err| die!(\"Write defaults config failure: {}\", err))\n        });\n\n    Config::load_from(\u0026*config_path).unwrap_or_else(|err| {\n        error!(\"Error: {}; Loading default config\", err);\n        Config::default()\n    })\n}\n\n/// Run Alacritty\n///\n/// Creates a window, the terminal state, pty, I/O event loop, input processor,\n/// config change monitor, and runs the main display loop.\nfn run(\n    mut config: Config,\n    options: \u0026cli::Options,\n    mut logger_proxy: LoggerProxy,\n) -\u003e Result\u003c(), Box\u003cError\u003e\u003e {\n    info!(\"Welcome to Alacritty.\");\n    if let Some(config_path) \u003d config.path() {\n        info!(\"Configuration loaded from {}\", config_path.display());\n    };\n\n    // Set environment variables\n    tty::setup_env(\u0026config);\n\n    // Create a display.\n    //\n    // The display manages a window and can draw the terminal\n    let mut display \u003d Display::new(\u0026config, options, logger_proxy.clone())?;\n\n    info!(\n        \"PTY Dimensions: {:?} x {:?}\",\n        display.size().lines(),\n        display.size().cols()\n    );\n\n    // Create the terminal\n    //\n    // This object contains all of the state about what\u0027s being displayed. It\u0027s\n    // wrapped in a clonable mutex since both the I/O loop and display need to\n    // access it.\n    let mut terminal \u003d Term::new(\u0026config, display.size().to_owned());\n    terminal.set_logger_proxy(logger_proxy.clone());\n    let terminal \u003d Arc::new(FairMutex::new(terminal));\n\n    // Find the window ID for setting $WINDOWID\n    let window_id \u003d display.get_window_id();\n\n    // Create the pty\n    //\n    // The pty forks a process to run the shell on the slave side of the\n    // pseudoterminal. A file descriptor for the master side is retained for\n    // reading/writing to the shell.\n    let pty \u003d tty::new(\u0026config, options, \u0026display.size(), window_id);\n\n    // Get a reference to something that we can resize\n    //\n    // This exists because rust doesn\u0027t know the interface is thread-safe\n    // and we need to be able to resize the PTY from the main thread while the IO\n    // thread owns the EventedRW object.\n    #[cfg(windows)]\n    let resize_handle \u003d unsafe { \u0026mut *pty.winpty.get() };\n    #[cfg(not(windows))]\n    let resize_handle \u003d \u0026mut pty.fd.as_raw_fd();\n\n    // Create the pseudoterminal I/O loop\n    //\n    // pty I/O is ran on another thread as to not occupy cycles used by the\n    // renderer and input processing. Note that access to the terminal state is\n    // synchronized since the I/O loop updates the state, and the display\n    // consumes it periodically.\n    let event_loop \u003d EventLoop::new(\n        Arc::clone(\u0026terminal),\n        display.notifier(),\n        pty,\n        options.ref_test,\n    );\n\n    // The event loop channel allows write requests from the event processor\n    // to be sent to the loop and ultimately written to the pty.\n    let loop_tx \u003d event_loop.channel();\n\n    // Event processor\n    //\n    // Need the Rc\u003cRefCell\u003c_\u003e\u003e here since a ref is shared in the resize callback\n    let mut processor \u003d event::Processor::new(\n        event_loop::Notifier(event_loop.channel()),\n        display.resize_channel(),\n        options,\n        \u0026config,\n        options.ref_test,\n        display.size().to_owned(),\n    );\n\n    // Create a config monitor when config was loaded from path\n    //\n    // The monitor watches the config file for changes and reloads it. Pending\n    // config changes are processed in the main loop.\n    let config_monitor \u003d match (options.live_config_reload, config.live_config_reload()) {\n        // Start monitor if CLI flag says yes\n        (Some(true), _) |\n        // Or if no CLI flag was passed and the config says yes\n        (None, true) \u003d\u003e config.path()\n                .map(|path| config::Monitor::new(path, display.notifier())),\n        // Otherwise, don\u0027t start the monitor\n        _ \u003d\u003e None,\n    };\n\n    // Kick off the I/O thread\n    let _io_thread \u003d event_loop.spawn(None);\n\n    info!(\"Initialisation complete\");\n\n    // Main display loop\n    loop {\n        // Process input and window events\n        let mut terminal_lock \u003d processor.process_events(\u0026terminal, display.window());\n\n        // Handle config reloads\n        if let Some(new_config) \u003d config_monitor\n            .as_ref()\n            .and_then(|monitor| monitor.pending_config())\n        {\n            config \u003d new_config.update_dynamic_title(options);\n            display.update_config(\u0026config);\n            processor.update_config(\u0026config);\n            terminal_lock.update_config(\u0026config);\n            terminal_lock.dirty \u003d true;\n        }\n\n        // Maybe draw the terminal\n        if terminal_lock.needs_draw() {\n            // Try to update the position of the input method editor\n            #[cfg(not(windows))]\n            display.update_ime_position(\u0026terminal_lock);\n\n            // Handle pending resize events\n            //\n            // The second argument is a list of types that want to be notified\n            // of display size changes.\n            display.handle_resize(\u0026mut terminal_lock, \u0026config, \u0026mut [resize_handle, \u0026mut processor]);\n\n            drop(terminal_lock);\n\n            // Draw the current state of the terminal\n            display.draw(\u0026terminal, \u0026config);\n        }\n\n        // Begin shutdown if the flag was raised.\n        if process_should_exit() {\n            break;\n        }\n    }\n\n    loop_tx\n        .send(Msg::Shutdown)\n        .expect(\"Error sending shutdown to event loop\");\n\n    // FIXME patch notify library to have a shutdown method\n    // config_reloader.join().ok();\n\n    // Without explicitly detaching the console cmd won\u0027t redraw it\u0027s prompt\n    #[cfg(windows)]\n    unsafe { FreeConsole(); }\n\n    info!(\"Goodbye.\");\n\n    if !options.persistent_logging \u0026\u0026 !config.persistent_logging() {\n        logger_proxy.delete_log();\n    }\n\n    Ok(())\n}\n"}}}
LSP4E to org.eclipse.corrosion.rls:Content-Length: 155


LSP4E to org.eclipse.corrosion.rls:{"jsonrpc":"2.0","id":"2","method":"textDocument/codeLens","params":{"textDocument":{"uri":"file:///Users/ihorantonov/dev/eclipse/alacritty/src/main.rs"}}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","method":"client/registerCapability","id":1,"params":{"registrations":[{"id":"rls-watch","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"/Users/ihorantonov/dev/eclipse/alacritty//Cargo.lock"},{"globPattern":"/Users/ihorantonov/dev/eclipse/alacritty//target","kind":4},{"globPattern":"/Users/ihorantonov/dev/eclipse/alacritty/Cargo.toml"},{"globPattern":"/Users/ihorantonov/dev/eclipse/alacritty/winpty/Cargo.toml"},{"globPattern":"/Users/ihorantonov/dev/eclipse/alacritty/servo-freetype-proxy/Cargo.toml"},{"globPattern":"/Users/ihorantonov/dev/eclipse/alacritty/copypasta/Cargo.toml"},{"globPattern":"/Users/ihorantonov/dev/eclipse/alacritty/font/Cargo.toml"}]}}]}}
LSP4E to org.eclipse.corrosion.rls:Content-Length: 38


LSP4E to org.eclipse.corrosion.rls:{"jsonrpc":"2.0","id":1,"result":null}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","id":2,"result":[]}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","method":"window/progress","params":{"done":true,"id":"progress_1","title":"Building"}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_0","title":"Indexing"}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","method":"window/showMessage","params":{"message":"Cargo failed: Error compiling dependent crate","type":1}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","method":"window/progress","params":{"done":true,"id":"progress_0","title":"Indexing"}}
LSP4E to org.eclipse.corrosion.rls:Content-Length: 200


LSP4E to org.eclipse.corrosion.rls:{"jsonrpc":"2.0","id":"3","method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/ihorantonov/dev/eclipse/alacritty/src/main.rs"},"position":{"line":0,"character":0}}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","id":3,"result":[]}
LSP4E to org.eclipse.corrosion.rls:Content-Length: 161


LSP4E to org.eclipse.corrosion.rls:{"jsonrpc":"2.0","id":"4","method":"textDocument/documentSymbol","params":{"textDocument":{"uri":"file:///Users/ihorantonov/dev/eclipse/alacritty/src/main.rs"}}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","id":4,"result":[]}

@ctron
Copy link
Author

ctron commented Nov 30, 2018

@mickaelistria Sorry, I didn't yet find the time to test this. The initial download aborted, then I lost track of this. I will try to do this.

@ctron
Copy link
Author

ctron commented Nov 30, 2018

I was finally able to try this. It shows the same behavior as with the other Eclipse installation. I was using 20181129-1705_eclipse-rust-2018-12-M3-linux.gtk.x86_64.

@ngortheone
Copy link

I have noticed a strange behavior
When lunched from CLI as @norru suggested:

RUST_LOG=rls=debug /path/to/your/eclipse &

RLS does not fail, builds everything successfully and starts indexing.

...
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","method":"window/progress","params":{"done":true,"id":"progress_1","title":"Building"}}
org.eclipse.corrosion.rls to LSP4E:{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_0","title":"Indexing"}}

But then I close Eclipse, and run it through macos launchpad it fails again on "failed to compile dependent crate".

My best guess is that there are some environment variable differences, or something that causes difference in behavior.

@norru
Copy link
Contributor

norru commented Dec 1, 2018

My best guess is that there are some environment variable differences, or something that causes difference in behavior.

It is a real possibility. I have encountered similar issues in the past and not just with Eclipse or Corrosion. Other things you may want to watch out for are $PWD and UID.

However, now at least you have a workaround!

What I often do on Linux is to create a small launcher script such as "eclipse_xx.yy_startup.sh" which sets up all the env vars for the session and then launches the actual IDE. I then add this script to whatever launcher/toolbar/start menu (not using macOS much these days though).

@mickaelistria
Copy link
Contributor

@ngortheone And when you try with just /path/to/eclipse in CLI, does it work? Ie is the difference caused by the RLS-debug property itself or just the fact of running from CLI?

@akurtakov
Copy link
Member

Is this still an issue?

@ctron
Copy link
Author

ctron commented Dec 18, 2018

Yes.

@pixilcode
Copy link

I was having this same problem. The RLS didn't seem to be working, but it worked when I would start it from the terminal. However, after looking at this comment, I ran cargo clean on each of the projects. After that, I started Eclipse from the UI Desktop and when it started up, the RLS worked as usual.

Try running cargo clean on all of your projects.

@pixilcode
Copy link

pixilcode commented Feb 7, 2019

However, later, the RLS turned off again. I'm not completely sure at what point. I had to run cargo clean on the project that I was working on and restart Eclipse for it to work again. All I was doing was writing code and running tests, along with using the Eclipse Git tool to make 1 commit, which only included lib.rs and Cargo.lock, which was created.

@mickaelistria
Copy link
Contributor

@ctron Does this still happen with the 2019-06 RC2 candidate?

@ctron
Copy link
Author

ctron commented Jun 12, 2019

@ctron Does this still happen with the 2019-06 RC2 candidate?

I just tested this with 2019-06 RC1 and it works now! Thanks!

Version: 2019-06 RC1 (4.12.0RC1)
Build id: 20190606-1049

Now I can see my code is full of issues 😁

@ctron ctron closed this as completed Jun 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants