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

Language server doesn't respond to initialize request properly #802

Closed
rozaliev opened this issue Jun 18, 2023 · 5 comments
Closed

Language server doesn't respond to initialize request properly #802

rozaliev opened this issue Jun 18, 2023 · 5 comments

Comments

@rozaliev
Copy link

I'm trying to make language-server work with Helix. But it looks like lsp doesn't respond to initialize request properly before sending its own requests. According to the spec:

Until the server has responded to the initialize request with an InitializeResult, the client must not send any additional requests or notifications to the server. In addition the server is not allowed to send any requests or notifications to the client until it has responded with an InitializeResult, with the exception that during the initialize request the server is allowed to send the notifications window/showMessage, window/logMessage and telemetry/event as well as the window/showMessageRequest request to the client.

Language server: @tailwindcss/language-server@0.0.13
tailwind-language-server --stdio

Expected:

-> {"jsonrpc":"2.0","method":"initialize","params":{ ... },"id":0}
<- {"jsonrpc":"2.0","id":0,"result": { ... }}

Received:

-> {"jsonrpc":"2.0","method":"initialize","params":{ ... },"id":0}
<- {"jsonrpc":"2.0","id":0,"method":"workspace/configuration","params":{"items":[{"section":"editor"}]}}
<- {"jsonrpc":"2.0","id":1,"method":"workspace/configuration","params":{"items":[{"section":"tailwindCSS"}]}}

I would assume that this line is the reason

let globalSettings = await getConfiguration()

And this these are the lines that send requests before the initialize response.

let [editor, tailwindCSS] = await Promise.all([

@atgote
Copy link
Contributor

atgote commented Jun 19, 2023

I can confirm absolutely the same behavior. I'm using vim 9.
However the same server binary works well with coc.nvim plugin but is not working with https://github.com/yegappan/lsp.

Looks like 'coc.nvim', 'VS Code' and others just 'supports dynamic registration' here and receive prompt response with caps:

if (supportsDynamicRegistration(connection, params)) {

all others go "long way" with await tw.init() - receiving configuration request instead...

After analysing the code I think that line

is the source of the bug and should be completely removed, since the init method is called after the connection is initialised from this line -

The 'yegappan/lsp' logs show the same records as shown above for 'Helix".

The 'coc.nvim' logs however show response correctly received for 'initialize':

[Trace - 20:23:19.544] Sending request 'initialize - (0)'.
Params: {...}


[Trace - 20:23:19.762] Received response 'initialize - (0)' in 219ms.
Result: {
    "capabilities": {
        "textDocumentSync": 1
    }
}


[Trace - 20:23:19.763] Sending notification 'initialized'.
Params: {}


[Trace - 20:23:19.770] Sending notification 'textDocument/didOpen'.
Params: {
    "textDocument": {
        "uri": "file:///home/.../label.component.html",
        "languageId": "html",
        "version": 1,
        "text": "..."
    }
}


[Trace - 20:23:19.770] Received request 'workspace/configuration - (0)'.
Params: {
    "items": [
        {
            "section": "editor"
        }
    ]
}


[Trace - 20:23:19.771] Sending response 'workspace/configuration - (0)'. Processing request took 1ms
Result: [
    {}
]

atgote added a commit to atgote/tailwindcss-intellisense that referenced this issue Jun 19, 2023
This is to resolve issue tailwindlabs#802
@atgote
Copy link
Contributor

atgote commented Jun 19, 2023

@rozaliev You may try to use my fork for testing (will require you to build packages lerna run build, set execution permission on the resulting packages/tailwindcss-landuage-server/dist/.../bin/tailwindcss-landuage-server and using path to this executable in your helix lsp config)

@rozaliev
Copy link
Author

@atgote thanks, your fork seems to work with Helix, at least for the initialization part and simple HTML editing.

But with custom regex, only completion works and hover doesn't. Here are the weird things I found in the logs:

2023-06-20T11:02:54.772 helix_lsp::transport [INFO] tailwind-hack -> {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"general":{"positionEncodings":["utf-8","utf-32","utf-16"]},"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"completion":{"completionItem":{"deprecatedSupport":true,"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]},"snippetSupport":true,"tagSupport":{"valueSet":[1]}},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]},"inlayHint":{"dynamicRegistration":false},"publishDiagnostics":{"versionSupport":true},"rename":{"dynamicRegistration":false,"honorsChangeAnnotations":false,"prepareSupport":true},"signatureHelp":{"signatureInformation":{"activeParameterSupport":true,"documentationFormat":["markdown"],"parameterInformation":{"labelOffsetSupport":true}}}},"window":{"workDoneProgress":true},"workspace":{"applyEdit":true,"configuration":true,"didChangeConfiguration":{"dynamicRegistration":false},"executeCommand":{"dynamicRegistration":false},"inlayHint":{"refreshSupport":false},"symbol":{"dynamicRegistration":false},"workspaceEdit":{"documentChanges":true,"failureHandling":"abort","normalizesLineEndings":false,"resourceOperations":["create","rename","delete"]},"workspaceFolders":true}},"clientInfo":{"name":"helix","version":"23.05"},"initializationOptions":{"tailwindCSS":{"experimental":{"classRegex":["class: \"(.*)\""]},"includedLanguages":{"rust":"html"}}},"processId":60856,"rootPath":"/mypath/diox_1","rootUri":"file:///mypath/diox_1","workspaceFolders":[{"name":"diox_1","uri":"file:///mypath/diox_1"}]},"id":0}


2023-06-20T11:02:55.493 helix_term::application [DEBUG] received editor event: LanguageServerMessage((0, MethodCall(MethodCall { jsonrpc: Some(V2), method: "client/registerCapability", params: Map({"registrations": Array [Object {"id": String("f96c2630-3ce7-4ec3-8b5d-d51b667f4dee"), "method": String("textDocument/hover"), "registerOptions": Object {"documentSelector": Null}}, Object {"id": String("c07e4872-a44f-4098-90d1-0597b761c22b"), "method": String("textDocument/documentColor"), "registerOptions": Object {"documentSelector": Null}}, Object {"id": String("6f3342de-6b09-4b1e-a069-51788dd061e6"), "method": String("textDocument/codeAction"), "registerOptions": Object {"documentSelector": Null}}, Object {"id": String("349075c1-391a-4393-847a-2ab7b1616e2e"), "method": String("textDocument/documentLink"), "registerOptions": Object {"documentSelector": Null}}, Object {"id": String("8db816d3-1c8c-41a6-a95e-75622fb8d660"), "method": String("textDocument/completion"), "registerOptions": Object {"documentSelector": Null, "resolveProvider": Bool(true), "triggerCharacters": Array [String("\""), String("'"), String("`"), String(" "), String("."), String("("), String("["), String("!"), String("/"), String(":")]}}]}), id: Num(4) })))

2023-06-20T11:02:55.493 helix_term::application [WARN] Ignoring a client/registerCapability request because dynamic capability registration is not enabled. Please report this upstream to the language server

I'm not sure if this is directly related to hover, because it works for HTML and shows similar errors. But it definitely seems like a bug, dynamicRegistration is clearly set to false by the client and is ignored.

@rozaliev
Copy link
Author

rozaliev commented Jun 20, 2023

I think I figured out how to make hover work with custom regex, but I'm not sure how to proceed since I'm not really familiar with Tailwind codebase and there are no tests.

I assume that somewhere around here should be code that handles includeLanguages and classRegex

I've added this line to test things out:

else {
    classNames = await findClassNamesInRange(state, doc, searchRange, 'html', true)
}

Notice the last argument, which sets includeCustom to true and enables classRegex

Everything seems to work with this change.

bradlc added a commit that referenced this issue Aug 22, 2023
* Remove buggy await call

This is to resolve issue #802

* Fix unhandled method errors

---------

Co-authored-by: Brad Cornes <hello@bradley.dev>
@bradlc
Copy link
Contributor

bradlc commented Aug 22, 2023

This should be fixed by #803 but please open a new issue if you're still running into problems 👍

We now automatically publish insiders releases for @tailwindcss/language-server, so until we publish a new latest release that's the one to try out (npm install @tailwindcss/language-server@insiders)

@bradlc bradlc closed this as completed Aug 22, 2023
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

3 participants