latex-lsp / texlab

An implementation of the Language Server Protocol for LaTeX
GNU General Public License v3.0
1.55k stars 53 forks source link

Texlab sends snippets in completion response even when client doesn't claim support #413

Closed bstaletic closed 3 years ago

bstaletic commented 3 years ago

According to the protocol, the server may only respond to textDocument/completion request with snippets (indicated with insertTextFormat == 2) if the client had claimed snippet support in the initial initialize request. However texlab doesn't respect that.

https://microsoft.github.io/language-server-protocol/specification#textDocument_completion

export interface CompletionClientCapabilities {
    /**
     * The client supports the following `CompletionItem` specific
     * capabilities.
     */
    completionItem?: {
        /**
         * Client supports snippets as insert text.
         *
         * A snippet can define tab stops and placeholders with `$1`, `$2`
         * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
         * the end of the snippet. Placeholders with equal identifiers are
         * linked, that is typing in one will update others too.
         */
        snippetSupport?: boolean;
        }
}
export namespace InsertTextFormat {
    export const PlainText = 1;
    export const Snippet = 2;
}
export type InsertTextFormat = 1 | 2;

Here are the exchanged messages between texlab and ycmd, which doesn't support snippets:

2021-05-13 14:47:31,259 - DEBUG - TX: Sending message: b'Content-Length: 1232\r\n\r\n{"id":1,"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"completion":{"completionItem":{"documentationFormat":["plaintext","markdown"]},"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]}},"documentSymbol":{"hierarchicalDocumentSymbolSupport":false,"labelSupport":false,"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]}},"hover":{"contentFormat":["plaintext","markdown"]},"signatureHelp":{"signatureInformation":{"documentationFormat":["plaintext","markdown"],"parameterInformation":{"labelOffsetSupport":true}}},"synchronization":{"didSave":true}},"workspace":{"applyEdit":true,"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"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]}},"workspaceEdit":{"documentChanges":true}}},"initializationOptions":{},"processId":9646,"rootPath":"/home/bstaletic/work/test","rootUri":"file:///home/bstaletic/work/test"}}'
2021-05-13 14:47:31,331 - DEBUG - RX: Received message: b'{"jsonrpc":"2.0","result":{"capabilities":{"completionProvider":{"resolveProvider":true,"triggerCharacters":["\\\\","{","}","@","/"," "]},"definitionProvider":true,"documentFormattingProvider":true,"documentHighlightProvider":true,"documentLinkProvider":{"resolveProvider":false},"documentSymbolProvider":true,"foldingRangeProvider":true,"hoverProvider":true,"referencesProvider":true,"renameProvider":{"prepareProvider":true},"textDocumentSync":{"change":1,"openClose":true,"save":{"includeText":false}},"workspaceSymbolProvider":true},"serverInfo":{"name":"TexLab","version":"2.2.2"}},"id":1}'
2021-05-13 14:47:31,332 - DEBUG - TX: Sending notification: b'Content-Length: 52\r\n\r\n{"jsonrpc":"2.0","method":"initialized","params":{}}'
2021-05-13 14:47:31,332 - DEBUG - TX: Sending notification: b'Content-Length: 86\r\n\r\n{"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{}}}'
2021-05-13 14:47:31,333 - DEBUG - TX: Sending notification: b'Content-Length: 572\r\n\r\n{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"tex","text":"\\\\documentclass[aps,pre,superscriptaddress]{revtex4-1}\\n\\\\usepackage{amssymb}\\n\\\\usepackage{amsmath}\\n\\\\usepackage{color}\\n\\\\begin{document}\\n\\\\title{Life, the Universe and Everything }\\n\\\\author{Douglas Adams}\\n\\\\begin{abstract}\\n42 is the answer\\n\\\\end{abstract}\\n\\\\date{\\\\today}\\n\\\\maketitle\\n\\\\section{Introduction}\\nbla bla\\n\\\\begin{eqnarray}\\n  x&=&y\\\\\\\\\\n  y&=&2\\n\\\\end{eqnarray}\\n\\\\end{document}\\n","uri":"file:///home/bstaletic/work/test/foo.tex","version":1}}}'
2021-05-13 14:47:35,067 - DEBUG - TX: Sending message: b'Content-Length: 172\r\n\r\n{"id":2,"jsonrpc":"2.0","method":"textDocument/completion","params":{"position":{"character":1,"line":7},"textDocument":{"uri":"file:///home/bstaletic/work/test/foo.tex"}}}'
2021-05-13 14:47:35,069 - DEBUG - RX: Received message: b'{"jsonrpc":"2.0","result":{"isIncomplete":false,"items":[{"data":"commandSnippet","detail":"built-in","insertText":"begin{$1}\\n\\t$0\\n\\\\end{$1}","insertTextFormat":2,"kind":15,"label":"begin","preselect":false,"sortText":"00"},{"data":"command","detail":"built-in","kind":3,"label":"begingroup","preselect":false,"sortText":"01","textEdit":{"newText":"begingroup","range":{"end":{"character":6,"line":7},"start":{"character":1,"line":7}}}},{"data":"command","detail":"built-in","kind":3,"label":"AtBeginDocument","preselect":false,"sortText":"02","textEdit":{"newText":"AtBeginDocument","range":{"end":{"character":6,"line":7},"start":{"character":1,"line":7}}}},{"data":"command","detail":"built-in","kind":3,"label":"AtBeginDvi","preselect":false,"sortText":"03","textEdit":{"newText":"AtBeginDvi","range":{"end":{"character":6,"line":7},"start":{"character":1,"line":7}}}}]},"id":2}'

That completion response ends up causing an assertion error and users see no completions.

pfoerster commented 3 years ago

Thanks for the report. This should be fixed with 426a1ec (PR: https://github.com/latex-lsp/texlab/pull/408).