Skip to content

File path completions unnecessarily escape trailing slashes for directories #180

@dbazile

Description

@dbazile

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 insertText property 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:

  1. Create new file
  2. Enter a string context where you can find file path completions
  3. Show completions menu
  4. Select a directory file path item from the completions menu
  5. See error

Expected behavior

It should enter the directory path without escaping the trailing slash.

Screenshots

demo.webm

Logs

:: [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): []

Environment (please complete the following information):

  • OS: Fedora 41
  • Sublime Text version: 4180
  • LSP version: 2.3.0
  • Language servers used: LSP-pylsp v2.21.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions