LSP's completions are adding unnecessary escapes to path separators on completion. They show correctly in the label and the completion picker but inserts an escape to the trailing slash, i.e. \/, making a lot of cleanup work to use this feature.
You can see in the logs and demo below that although the label has the correct path, the insertText property has escaped trailing slashes for some reason.
It should enter the directory path without escaping the trailing slash.
:: [12:59:43.900] --> LSP-pylsp textDocument/codeAction (118): {'textDocument': {'uri': 'file:///home/david/deleteme/test.py'}, 'range': {'start': {'line': 0, 'character': 7}, 'end': {'line': 0, 'character': 7}}, 'context': {'diagnostics': [], 'triggerKind': 1, 'only': [<CodeActionKind.Refactor: 'refactor'>, <CodeActionKind.Source: 'source'>]}}
:: [12:59:43.900] <<< LSP-pylsp (117) (duration: 6ms): []
:: [12:59:43.900] <<< LSP-pylsp (118) (duration: 0ms): []
:: [12:59:54.240] --> LSP-pylsp textDocument/completion (119): {'textDocument': {'uri': 'file:///home/david/deleteme/test.py'}, 'position': {'line': 0, 'character': 7}}
:: [12:59:54.241] <<< LSP-pylsp (119) (duration: 1ms): {'isIncomplete': False, 'items': [{'label': 'lorem/', 'kind': 17, 'sortText': 'alorem/', 'insertText': 'lorem\\/', 'data': {'doc_uri': 'file:///home/david/deleteme/test.py'}}, {'label': 'test.py', 'kind': 17, 'sortText': 'atest.py', 'insertText': 'test.py', 'data': {'doc_uri': 'file:///home/david/deleteme/test.py'}}]}
:: [12:59:57.896] --> LSP-pylsp completionItem/resolve (120): {'label': 'lorem/', 'kind': 17, 'sortText': 'alorem/', 'insertText': 'lorem\\/', 'data': {'doc_uri': 'file:///home/david/deleteme/test.py'}}
:: [12:59:57.898] <<< LSP-pylsp (120) (duration: 2ms): {'label': 'lorem/', 'kind': 17, 'sortText': 'alorem/', 'insertText': 'lorem\\/', 'data': {'doc_uri': 'file:///home/david/deleteme/test.py'}, 'detail': '', 'documentation': {'kind': 'markdown', 'value': '```\n\n```\n'}}
:: [12:59:57.898] -> LSP-pylsp textDocument/didChange: {'textDocument': {'uri': 'file:///home/david/deleteme/test.py', 'version': 3}, 'contentChanges': [{'range': {'start': {'line': 0, 'character': 7}, 'end': {'line': 0, 'character': 7}}, 'rangeLength': 0, 'text': 'lorem\\/'}]}
:: [12:59:57.898] --> LSP-pylsp textDocument/completion (121): {'textDocument': {'uri': 'file:///home/david/deleteme/test.py'}, 'position': {'line': 0, 'character': 14}}
:: [12:59:57.899] <<< LSP-pylsp (121) (duration: 1ms): {'isIncomplete': False, 'items': []}
:: [12:59:58.197] --> LSP-pylsp textDocument/codeLens (122): {'textDocument': {'uri': 'file:///home/david/deleteme/test.py'}}
:: [12:59:58.197] <<< LSP-pylsp (122) (duration: 0ms): []
:: [12:59:58.199] --> LSP-pylsp textDocument/documentHighlight (123): {'textDocument': {'uri': 'file:///home/david/deleteme/test.py'}, 'position': {'line': 0, 'character': 14}}
:: [12:59:58.200] <<< LSP-pylsp (123) (duration: 0ms): None
:: [12:59:58.399] <-- LSP-pylsp window/workDoneProgress/create (b2e2f1ab-9db3-4c80-b3b8-3f2815b0f391): {'token': '368c0b08-17a4-444a-bb13-5369635141fc'}
:: [12:59:58.399] >>> LSP-pylsp (b2e2f1ab-9db3-4c80-b3b8-3f2815b0f391) (duration: 0ms): None
:: [12:59:58.399] <- LSP-pylsp $/progress: {'token': '368c0b08-17a4-444a-bb13-5369635141fc', 'value': {'kind': 'begin', 'title': 'lint: flake8'}}
LSP-pylsp: 2025-01-12 12:59:58,462 CST - ERROR - pylsp.plugins.flake8_lint - Error while running flake8 '<unknown>:1: SyntaxWarning: invalid escape sequence '\/'
LSP-pylsp: '
:: [12:59:58.462] <- LSP-pylsp $/progress: {'token': '368c0b08-17a4-444a-bb13-5369635141fc', 'value': {'kind': 'end'}}
:: [12:59:58.464] <- LSP-pylsp textDocument/publishDiagnostics: {'uri': 'file:///home/david/deleteme/test.py', 'diagnostics': [{'source': 'flake8', 'code': 'W605', 'range': {'start': {'line': 0, 'character': 12}, 'end': {'line': 0, 'character': 17}}, 'message': "W605 invalid escape sequence '\\/'", 'severity': 2}], 'version': 3}
:: [12:59:58.465] --> LSP-pylsp textDocument/codeAction (124): {'textDocument': {'uri': 'file:///home/david/deleteme/test.py'}, 'range': {'start': {'line': 0, 'character': 12}, 'end': {'line': 0, 'character': 16}}, 'context': {'diagnostics': [{'source': 'flake8', 'code': 'W605', 'range': {'start': {'line': 0, 'character': 12}, 'end': {'line': 0, 'character': 17}}, 'message': "W605 invalid escape sequence '\\/'", 'severity': 2}], 'triggerKind': 2}}
:: [12:59:58.465] <<< LSP-pylsp (124) (duration: 0ms): []
Describe the bug
LSP's completions are adding unnecessary escapes to path separators on completion. They show correctly in the label and the completion picker but inserts an escape to the trailing slash, i.e.
\/, making a lot of cleanup work to use this feature.You can see in the logs and demo below that although the label has the correct path, the
insertTextproperty has escaped trailing slashes for some reason.Previously submitted this at LSP but they said it was a language server issue: sublimelsp/LSP#2585.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
It should enter the directory path without escaping the trailing slash.
Screenshots
demo.webm
Logs
Environment (please complete the following information):
Fedora 4141802.3.0LSP-pylsp v2.21.0