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

Server shutting down after sending textDocument/hover #1600

Open
JoeDinn opened this issue Jan 18, 2025 · 8 comments
Open

Server shutting down after sending textDocument/hover #1600

JoeDinn opened this issue Jan 18, 2025 · 8 comments
Labels
info-needed Issue requires more information from poster

Comments

@JoeDinn
Copy link

JoeDinn commented Jan 18, 2025

I am trying to implement a language server with a vscode extension

Currently all I amtrying to get working is hover
The initialisation messages seem to be working but when the client sends the hover message the client errors:

[Error - 7:08:38 PM] Stopping server failed
Error: Stopping the server timed out
at /path/to/extension/client/node_modules/vscode-languageclient/lib/common/client.js:933:23

This is the response we send:
"Content-Length: 104\r\n\r\n{"jsonrpc":"2.0","id":1,"result":{"contents":{"value":"Showing help text for\nnil","kind":"plaintext"}}}"

but it doesn't get logged in the trace
My guess is that it's taking too long to recieve the response and assuming that the server is down - is there a way of checking this or increasing the timeout?

Here are the messages sent and recieved by the client:

`[Trace - 7:08:07 PM] Sending request 'initialize - (0)'.
Params: {
"processId": 2961119,
"clientInfo": {
"name": "Visual Studio Code",
"version": "1.96.2"
},
"locale": "en",
"rootPath": "/path/to/workspace",
"rootUri": "file:///path/to/workspace",
"capabilities": {
"workspace": {
"applyEdit": true,
"workspaceEdit": {
"documentChanges": true,
"resourceOperations": [
"create",
"rename",
"delete"
],
"failureHandling": "textOnlyTransactional",
"normalizesLineEndings": true,
"changeAnnotationSupport": {
"groupsOnLabel": true
}
},
"configuration": true,
"didChangeWatchedFiles": {
"dynamicRegistration": true,
"relativePatternSupport": true
},
"symbol": {
"dynamicRegistration": true,
"symbolKind": {
"valueSet": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26
]
},
"tagSupport": {
"valueSet": [
1
]
},
"resolveSupport": {
"properties": [
"location.range"
]
}
},
"codeLens": {
"refreshSupport": true
},
"executeCommand": {
"dynamicRegistration": true
},
"didChangeConfiguration": {
"dynamicRegistration": true
},
"workspaceFolders": true,
"semanticTokens": {
"refreshSupport": true
},
"fileOperations": {
"dynamicRegistration": true,
"didCreate": true,
"didRename": true,
"didDelete": true,
"willCreate": true,
"willRename": true,
"willDelete": true
},
"inlineValue": {
"refreshSupport": true
},
"inlayHint": {
"refreshSupport": true
},
"diagnostics": {
"refreshSupport": true
}
},
"textDocument": {
"publishDiagnostics": {
"relatedInformation": true,
"versionSupport": false,
"tagSupport": {
"valueSet": [
1,
2
]
},
"codeDescriptionSupport": true,
"dataSupport": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
},
"completion": {
"dynamicRegistration": true,
"contextSupport": true,
"completionItem": {
"snippetSupport": true,
"commitCharactersSupport": true,
"documentationFormat": [
"markdown",
"plaintext"
],
"deprecatedSupport": true,
"preselectSupport": true,
"tagSupport": {
"valueSet": [
1
]
},
"insertReplaceSupport": true,
"resolveSupport": {
"properties": [
"documentation",
"detail",
"additionalTextEdits"
]
},
"insertTextModeSupport": {
"valueSet": [
1,
2
]
},
"labelDetailsSupport": true
},
"insertTextMode": 2,
"completionItemKind": {
"valueSet": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25
]
},
"completionList": {
"itemDefaults": [
"commitCharacters",
"editRange",
"insertTextFormat",
"insertTextMode"
]
}
},
"hover": {
"dynamicRegistration": true,
"contentFormat": [
"markdown",
"plaintext"
]
},
"signatureHelp": {
"dynamicRegistration": true,
"signatureInformation": {
"documentationFormat": [
"markdown",
"plaintext"
],
"parameterInformation": {
"labelOffsetSupport": true
},
"activeParameterSupport": true
},
"contextSupport": true
},
"definition": {
"dynamicRegistration": true,
"linkSupport": true
},
"references": {
"dynamicRegistration": true
},
"documentHighlight": {
"dynamicRegistration": true
},
"documentSymbol": {
"dynamicRegistration": true,
"symbolKind": {
"valueSet": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26
]
},
"hierarchicalDocumentSymbolSupport": true,
"tagSupport": {
"valueSet": [
1
]
},
"labelSupport": true
},
"codeAction": {
"dynamicRegistration": true,
"isPreferredSupport": true,
"disabledSupport": true,
"dataSupport": true,
"resolveSupport": {
"properties": [
"edit"
]
},
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"",
"quickfix",
"refactor",
"refactor.extract",
"refactor.inline",
"refactor.rewrite",
"source",
"source.organizeImports"
]
}
},
"honorsChangeAnnotations": false
},
"codeLens": {
"dynamicRegistration": true
},
"formatting": {
"dynamicRegistration": true
},
"rangeFormatting": {
"dynamicRegistration": true
},
"onTypeFormatting": {
"dynamicRegistration": true
},
"rename": {
"dynamicRegistration": true,
"prepareSupport": true,
"prepareSupportDefaultBehavior": 1,
"honorsChangeAnnotations": true
},
"documentLink": {
"dynamicRegistration": true,
"tooltipSupport": true
},
"typeDefinition": {
"dynamicRegistration": true,
"linkSupport": true
},
"implementation": {
"dynamicRegistration": true,
"linkSupport": true
},
"colorProvider": {
"dynamicRegistration": true
},
"foldingRange": {
"dynamicRegistration": true,
"rangeLimit": 5000,
"lineFoldingOnly": true,
"foldingRangeKind": {
"valueSet": [
"comment",
"imports",
"region"
]
},
"foldingRange": {
"collapsedText": false
}
},
"declaration": {
"dynamicRegistration": true,
"linkSupport": true
},
"selectionRange": {
"dynamicRegistration": true
},
"callHierarchy": {
"dynamicRegistration": true
},
"semanticTokens": {
"dynamicRegistration": true,
"tokenTypes": [
"namespace",
"type",
"class",
"enum",
"interface",
"struct",
"typeParameter",
"parameter",
"variable",
"property",
"enumMember",
"event",
"function",
"method",
"macro",
"keyword",
"modifier",
"comment",
"string",
"number",
"regexp",
"operator",
"decorator"
],
"tokenModifiers": [
"declaration",
"definition",
"readonly",
"static",
"deprecated",
"abstract",
"async",
"modification",
"documentation",
"defaultLibrary"
],
"formats": [
"relative"
],
"requests": {
"range": true,
"full": {
"delta": true
}
},
"multilineTokenSupport": false,
"overlappingTokenSupport": false,
"serverCancelSupport": true,
"augmentsSyntaxTokens": true
},
"linkedEditingRange": {
"dynamicRegistration": true
},
"typeHierarchy": {
"dynamicRegistration": true
},
"inlineValue": {
"dynamicRegistration": true
},
"inlayHint": {
"dynamicRegistration": true,
"resolveSupport": {
"properties": [
"tooltip",
"textEdits",
"label.tooltip",
"label.location",
"label.command"
]
}
},
"diagnostic": {
"dynamicRegistration": true,
"relatedDocumentSupport": false
}
},
"window": {
"showMessage": {
"messageActionItem": {
"additionalPropertiesSupport": true
}
},
"showDocument": {
"support": true
},
"workDoneProgress": true
},
"general": {
"staleRequestSupport": {
"cancel": true,
"retryOnContentModified": [
"textDocument/semanticTokens/full",
"textDocument/semanticTokens/range",
"textDocument/semanticTokens/full/delta"
]
},
"regularExpressions": {
"engine": "ECMAScript",
"version": "ES2020"
},
"markdown": {
"parser": "marked",
"version": "1.1.0"
},
"positionEncodings": [
"utf-16"
]
},
"notebookDocument": {
"synchronization": {
"dynamicRegistration": true,
"executionSummarySupport": true
}
}
},
"trace": "verbose",
"workspaceFolders": [
{
"uri": "file:///path/to/workspace,
"name": "test"
}
]
}

[Trace - 7:08:14 PM] Received response 'initialize - (0)' in 7018ms.
Result: {
"capabilities": {
"hoverProvider": "true"
}
}

[Trace - 7:08:14 PM] Sending notification 'initialized'.
Params: {}

[Trace - 7:08:35 PM] Sending request 'textDocument/hover - (1)'.
Params: {
"textDocument": {
"uri": "file:///path/to/document.ext"
},
"position": {
"line": 4,
"character": 9
}
}

[Error - 7:08:36 PM] Client Skill Language Server: connection to server is erroring. Shutting down server.
[Trace - 7:08:36 PM] Sending request 'shutdown - (2)'.
[Trace - 7:08:37 PM] Sending notification '$/cancelRequest'.
Params: {
"id": 1
}

`

@dbaeumer
Copy link
Member

Hard to say. Have you tried to debug the server. Errors like this occur when the server for some reason closes the connection or the connection gets lost otherwise.

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Jan 20, 2025
@JoeDinn
Copy link
Author

JoeDinn commented Jan 20, 2025

How can the server close the connection? What sort of thing should I be looking for when debugging? Is there any way to get more info from the client about why the connection is erroring?

@rcjsuen
Copy link
Contributor

rcjsuen commented Jan 20, 2025

My guess is that it's taking too long to recieve the response and assuming that the server is down - is there a way of checking this or increasing the timeout?

I am not sure that "taking a long time" would cause VS Code to terminate your server. Have you tried changing your textDocument/hover handler on the server to just return immediately instead of doing whatever calculations it needs to perform to validate your hypothesis?

@JoeDinn
Copy link
Author

JoeDinn commented Jan 20, 2025

Have you tried changing your textDocument/hover handler on the server to just return immediately instead of doing whatever calculations it needs to perform to validate your hypothesis?

I tried putting some timestamps in and it seems to be sending the response almost instantly so that probably isn't the problem

What kinds of things do you think could cause the client to terminate the server? Would it do so if it got an invalid response?

@rcjsuen
Copy link
Contributor

rcjsuen commented Jan 21, 2025

What kinds of things do you think could cause the client to terminate the server? Would it do so if it got an invalid response?

Perhaps you could start by putting a breakpoint here to try and see what's going on.

@JoeDinn
Copy link
Author

JoeDinn commented Jan 22, 2025

Perhaps you could start by putting a breakpoint here to try and see what's going on.

I was able to find the problem by breaking here, thanks!

The way we are sending the jsonrpc responses adds a newline to the end of the message but this isn't accounted for when we calculate the content message length so the \n is left in the buffer and gets added to the next response, which breaks it because the client is looking for "content-length" not "\ncontent-length". It supposedly throws the error "Header must provide a Content-length property" but I never saw this anywhere - where should it be dumped to?

Can I suggest that when it errors in this way it dumps the whole response string it recieved to the console? It would have made the debugging much simpler. Until putting the breakpoint in I didn't even know if it had received the response or not. I would have thought writing slightly wrong responses is one of the most common ways for a language server to fail so it would be nice for the client to be looking out for that and giving a more helpful message than just that the connection is erroring

Thanks again for your help!

@rcjsuen
Copy link
Contributor

rcjsuen commented Jan 22, 2025

Can I suggest that when it errors in this way it dumps the whole response string it recieved to the console? It would have made the debugging much simpler.

I imagine this isn't the first time this has happened to someone. I can't comment on this as I'm not a maintainer of this project.

@dbaeumer
Copy link
Member

Actually the error message should be logged here: https://github.com/microsoft/vscode-languageserver-node/blob/main/client/src/common/client.ts#L1823

Did you not see the text in the output panel of the LSP client instance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants