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

Ruby LSP always attempts to index the current working directory #2382

Closed
etherbob opened this issue Jul 29, 2024 · 5 comments · Fixed by #2424
Closed

Ruby LSP always attempts to index the current working directory #2382

etherbob opened this issue Jul 29, 2024 · 5 comments · Fixed by #2424
Assignees
Labels
bug Something isn't working

Comments

@etherbob
Copy link

Description

Reproduction steps

  1. On MacOS
  2. Start the Ruby LSP using BBEdit's lsp support, replacing solargraph with ruby-lsp
  3. run tail -f $HOME/Library/Containers/com.barebones.bbedit/Data/Library/Logs/BBEdit/LanguageServerProtocol-Ruby.txt
  4. Open a Ruby file
  5. ruby-lsp will attempt to index your home directory regardless of the workspace config BBEdit passes in at initialization time or when opening code in various working directories.

Code snippet or error message

2024-07-24 21:06:50.722: Server message (error): Error while indexing: Operation not permitted - /Users/<username>/Library/Application Support/com.apple.LaunchServicesTemplateApp.dv
@etherbob etherbob added the bug Something isn't working label Jul 29, 2024
@vinistock
Copy link
Member

Thank you for the bug report!

Let me double-check if I understand the issue correctly. We do want to index all of the files in the workspace you are working on (otherwise your project declarations would not be available for go to definition, hover, etc).

What you're noticing is that BBEdit spawns the language server process using a cwd that isn't the same as the path to your workspace. Is that correct?

If my understanding is right, then we need to pass down the workspace URI used to activate the server during the initialization request to the indexer so that we rely on that instead of Dir.pwd.

@etherbob
Copy link
Author

etherbob commented Aug 7, 2024

I think so. This is what BBEdit sends on startup.

2024-07-26 15:40:06.478: Initialization parameters sent to server: {
    capabilities =     {
        textDocument =         {
            codeAction =             {
                codeActionLiteralSupport =                 {
                    codeActionKind =                     {
                        valueSet =                         (
                            info,
                            quickfix,
                            refactor,
                            source
                        );
                    };
                };
            };
            completion =             {
                completionItem =                 {
                    deprecatedSupport = 1;
                    documentationFormat =                     (
                        markdown,
                        plaintext
                    );
                    insertReplaceSupport = 1;
                    insertTextModeSupport =                     {
                        valueSet =                         (
                            1,
                            2
                        );
                    };
                    preselectSupport = 1;
                    snippetSupport = 1;
                };
            };
            documentSymbol =             {
                hierarchicalDocumentSymbolSupport = 1;
                labelSupport = 1;
            };
            hover =             {
                contentFormat =                 (
                    markdown,
                    plaintext
                );
            };
            onTypeFormatting =             {
            };
            publishDiagnostics =             {
                categorySupport = 1;
                codeActionsInline = 1;
                codeDescription = 1;
                dataSupport = 1;
                relatedInformation = 1;
            };
            rename =             {
                prepareSupport = 1;
                prepareSupportDefaultBehavior = 1;
            };
            signatureHelp =             {
                signatureInformation =                 {
                    activeParameterSupport = 1;
                    documentationFormat =                     (
                        markdown,
                        plaintext
                    );
                    parameterInformation =                     {
                        labelOffsetSupport = 1;
                    };
                };
            };
            synchronization =             {
                didSave = 1;
                willSave = 1;
            };
        };
        workspace =         {
            applyEdit = 1;
            configuration = 1;
            workspaceEdit =             {
                documentChanges = 0;
                failureHandling = abort;
            };
            workspaceFolders = 1;
        };
    };
    clientInfo =     {
        name = BBEdit;
        version = "15.1.2";
    };
    initializationOptions =     {
        diagnostics = 1;
    };
    rootUri = "file:///Users/username/dev/project/";
    trace = verbose;
    workspaceFolders =     (
                {
            name = "project";
            uri = "file:///Users/username/dev/project/";
        }
    );
}

@vinistock
Copy link
Member

Okay, so the workspace URI is "file:///Users/username/dev/project/", which surely is the project where you're opening the editor.

To confirm our understanding, can you please edit the Ruby LSP's code in place and print the Dir.pwd? If our understanding is right and Dir.pwd does not match the workspace URI, then we identified the issue and I know what the fix is.

  1. BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle open ruby-lsp (open the Ruby LSP for editing)
  2. In top of the internal file, which is our initial require, add the following (note: it must be printed to stderr because printing to stdout breaks the editor/server communication)
$stderr.puts("PWD: #{Dir.pwd}")
  1. Go to VS Code's Output tab under the Ruby LSP channel and search for PWD:

@etherbob
Copy link
Author

etherbob commented Aug 8, 2024

Probably worth noting this is not in VSCode
2024-08-08 16:54:06.335: stderr output from server: PWD: /Users/username

@vinistock
Copy link
Member

Sorry, yeah, I said VS Code, but I just cared about the output. Indeed, our understanding was confirmed an BBEdit launches the language server process in a directory that isn't the workspace you are working on.

#2424 will improve the situation, but there is a caveat explanation in the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants