Lsp: Completion prefix not removed properly on completing fast

Created on 12 Aug 2020  路  26Comments  路  Source: sublimelsp/LSP

weird_completion

Please include in your report:

  • Mac OS / LSP-intelephense / Sublime Text 4 (4081)
  • Installed from Package Control
  • Type a statement (like $foo = 'bar';, then go back to add a function to wrap 'bar', like json_decode), notice that part of the completion prefixes the full completion, ending up with something like:

I haven't been able to reproduce it again to get a log, but when I do I will be sure to attach that as well. It has happened several times over the past few days.

fixed sublime issue

Most helpful comment

The new alpha build 4086 mentions fixes relating to the prefix removal. Perhaps this is now fixed?

All 26 comments

Yay, got the log!

Unable to open /Users/rmcquen/Library/Application Support/Sublime Text 3/Packages/LSP/LSP.sublime-settings
reloading settings Packages/User/LSP.sublime-settings
Unable to open /Users/rmcquen/Library/Application Support/Sublime Text 3/Packages/LSP/LSP.sublime-settings
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 1381, in run_
    self.view.end_edit(edit)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 1072, in end_edit
    sublime_api.view_end_edit(self.view_id, edit.edit_token)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 846, in on_modified
    run_view_callbacks('on_modified', view_id)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 665, in run_view_callbacks
    callback(v, *args)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 147, in profiler
    return event_handler(*args)
  File "/Users/rmcquen/Library/Application Support/Sublime Text 3/Installed Packages/AutoFileName.sublime-package/autofilename.py", line 162, in on_modified
    sel = view.sel()[0].a
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 846, in __getitem__
    raise IndexError()
IndexError
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 1381, in run_
    self.view.end_edit(edit)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 1072, in end_edit
    sublime_api.view_end_edit(self.view_id, edit.edit_token)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 854, in on_selection_modified
    run_view_callbacks('on_selection_modified', view_id)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 665, in run_view_callbacks
    callback(v, *args)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 147, in profiler
    return event_handler(*args)
  File "/Users/rmcquen/Library/Application Support/Sublime Text 3/Installed Packages/Persistent Status Bar Line Number.sublime-package/persistent_status_bar_line_number.py", line 8, in on_selection_modified
    view.sel()[0].begin()
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 846, in __getitem__
    raise IndexError()
IndexError
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 1381, in run_
    self.view.end_edit(edit)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 1072, in end_edit
    sublime_api.view_end_edit(self.view_id, edit.edit_token)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 846, in on_modified
    run_view_callbacks('on_modified', view_id)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 665, in run_view_callbacks
    callback(v, *args)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 147, in profiler
    return event_handler(*args)
  File "/Users/rmcquen/Library/Application Support/Sublime Text 3/Installed Packages/AutoFileName.sublime-package/autofilename.py", line 162, in on_modified
    sel = view.sel()[0].a
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 846, in __getitem__
    raise IndexError()
IndexError
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 1381, in run_
    self.view.end_edit(edit)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 1072, in end_edit
    sublime_api.view_end_edit(self.view_id, edit.edit_token)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 854, in on_selection_modified
    run_view_callbacks('on_selection_modified', view_id)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 665, in run_view_callbacks
    callback(v, *args)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 147, in profiler
    return event_handler(*args)
  File "/Users/rmcquen/Library/Application Support/Sublime Text 3/Installed Packages/Persistent Status Bar Line Number.sublime-package/persistent_status_bar_line_number.py", line 8, in on_selection_modified
    view.sel()[0].begin()
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 846, in __getitem__
    raise IndexError()
IndexError
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 1381, in run_
    self.view.end_edit(edit)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 1072, in end_edit
    sublime_api.view_end_edit(self.view_id, edit.edit_token)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 846, in on_modified
    run_view_callbacks('on_modified', view_id)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 665, in run_view_callbacks
    callback(v, *args)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 147, in profiler
    return event_handler(*args)
  File "/Users/rmcquen/Library/Application Support/Sublime Text 3/Installed Packages/AutoFileName.sublime-package/autofilename.py", line 162, in on_modified
    sel = view.sel()[0].a
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 846, in __getitem__
    raise IndexError()
IndexError
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 1381, in run_
    self.view.end_edit(edit)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 1072, in end_edit
    sublime_api.view_end_edit(self.view_id, edit.edit_token)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 854, in on_selection_modified
    run_view_callbacks('on_selection_modified', view_id)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 665, in run_view_callbacks
    callback(v, *args)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 147, in profiler
    return event_handler(*args)
  File "/Users/rmcquen/Library/Application Support/Sublime Text 3/Installed Packages/Persistent Status Bar Line Number.sublime-package/persistent_status_bar_line_number.py", line 8, in on_selection_modified
    view.sel()[0].begin()
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 846, in __getitem__
    raise IndexError()
IndexError
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 1381, in run_
    self.view.end_edit(edit)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 1072, in end_edit
    sublime_api.view_end_edit(self.view_id, edit.edit_token)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 846, in on_modified
    run_view_callbacks('on_modified', view_id)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 665, in run_view_callbacks
    callback(v, *args)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 147, in profiler
    return event_handler(*args)
  File "/Users/rmcquen/Library/Application Support/Sublime Text 3/Installed Packages/AutoFileName.sublime-package/autofilename.py", line 162, in on_modified
    sel = view.sel()[0].a
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 846, in __getitem__
    raise IndexError()
IndexError
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 1381, in run_
    self.view.end_edit(edit)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 1072, in end_edit
    sublime_api.view_end_edit(self.view_id, edit.edit_token)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 854, in on_selection_modified
    run_view_callbacks('on_selection_modified', view_id)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 665, in run_view_callbacks
    callback(v, *args)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 147, in profiler
    return event_handler(*args)
  File "/Users/rmcquen/Library/Application Support/Sublime Text 3/Installed Packages/Persistent Status Bar Line Number.sublime-package/persistent_status_bar_line_number.py", line 8, in on_selection_modified
    view.sel()[0].begin()
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 846, in __getitem__
    raise IndexError()
IndexError

There seems to be something really wrong with your ST if you are getting errors like

Unable to open /Users/rmcquen/Library/Application Support/Sublime Text 3/Packages/LSP/LSP.sublime-settings

Also notice that all of those stack traces are related to other packages.

I am on ST4.

Actually that might not be a problem. It probably means that you've opened LSP settings and you don't have any customizations.
But all in all none of that seems related to your original issue.

Yeah, I can't get anything useful from the log but I am repro-ing the issue semi regularly. Here's my full package list if it helps:

{
    "bootstrapped": true,
    "in_process_packages":
    [
    ],
    "installed_packages":
    [
        "AutoFileName",
        "AutoPEP8",
        "Babel",
        "Clang Format",
        "DashDoc",
        "Debugger",
        "DiffTabs",
        "Dockerfile Syntax Highlighting",
        "DotENV",
        "DoxyDoxygen",
        "EditorConfig",
        "FileDiffs",
        "fish",
        "Function Name Display",
        "Gremlins",
        "JsPrettier",
        "LSP",
        "LSP-intelephense",
        "LSP-typescript",
        "MarkdownPreview",
        "Nord",
        "Package Control",
        "Persistent Status Bar Line Number",
        "PHP-Twig",
        "RawLineEdit",
        "RESTer HTTP Client",
        "RustFmt",
        "Sass",
        "SendToPasteBin",
        "StandardFormat",
        "SublimeLinter",
        "SublimeLinter-contrib-phpstan",
        "SublimeLinter-contrib-standard",
        "SublimeLinter-php",
        "Terminus",
        "uroboroSQL Formatter",
        "Witness color scheme",
    ],
    "repositories":
    [
    ],
}

I'm having this same problem with clangd so I'm guessing this is not a language specific issue. The only reproduction steps that I've managed to quantify is to use the arrow keys to select a completion and the whole thing fails immediately

Issue in action: https://imgur.com/a/haXUaAd

My LSP troubleshoot output is below.

Troubleshooting: clangd

Version

  • LSP: 1.0.9
  • Sublime Text: 4084

    Server Test Run

  • exit code: 0

  • output
I[11:03:40.720] clangd version 9.0.0 (tags/RELEASE_900/final)
I[11:03:40.721] Working directory: C:\Users\Robert\Documents\E01
I[11:03:40.721] argv[0]: clangd
I[11:03:40.721] Starting LSP over stdin/stdout

Server Configuration

  • command
[
  "clangd"
]
  • shell command
clangd
  • languages
[
  {
    "document_selector": "source.c", 
    "feature_selector": "source.c", 
    "language_id": "c"
  }, 
  {
    "document_selector": "source.c++", 
    "feature_selector": "source.c++", 
    "language_id": "cpp"
  }, 
  {
    "document_selector": "source.objc", 
    "feature_selector": "source.objc", 
    "language_id": "objective-c"
  }, 
  {
    "document_selector": "source.objc++", 
    "feature_selector": "source.objc++", 
    "language_id": "objective-cpp"
  }
]
  • init_options
{}
  • settings
{}
  • env
{}

Active view

  • File name
C:\Users\Robert\Documents\E01\asset-builder\AssetBuilder.cpp
  • Settings
{
  "auto_complete_selector": "meta.tag, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc", 
  "lsp_active": true, 
  "syntax": "Packages/C++/C++.sublime-syntax"
}

Project / Workspace

  • folders
[
  "C:\\Users\\Robert\\Documents\\E01"
]
  • is project: True
  • project data:
{
  "build_systems": [
    {
      "cmd": [
        "vcvars64.bat", 
        "&&", 
        "nmake", 
        "/NOLOGO", 
        "/f", 
        "Makefile", 
        "main"
      ], 
      "file_regex": "([^\\n]+?\\.cpp)\\((\\d+),(\\d+)\\) *: *error: *([^\\n]+)", 
      "name": "Build", 
      "shell": true, 
      "variants": [
        {
          "cmd": [
            "vcvars64.bat", 
            "&&", 
            "nmake", 
            "/NOLOGO", 
            "/f", 
            "Makefile", 
            "main", 
            "&&", 
            "main.exe"
          ], 
          "name": "Build & Run", 
          "shell": true
        }, 
        {
          "cmd": [
            "remedybg.exe", 
            "open-file", 
            "${file}"
          ], 
          "name": "Debug File"
        }, 
        {
          "cmd": [
            "main.exe"
          ], 
          "name": "Run"
        }, 
        {
          "cmd": [
            "vcvars64.bat", 
            "&&", 
            "nmake", 
            "/NOLOGO", 
            "/f", 
            "Makefile", 
            "clean"
          ], 
          "name": "Clean", 
          "shell": true
        }, 
        {
          "cmd": [
            "python", 
            "sync-files.py"
          ], 
          "name": "Sync Files", 
          "working_dir": "${project_path}/.."
        }
      ], 
      "working_dir": "${project_path}"
    }
  ], 
  "folders": [
    {
      "path": "../"
    }
  ], 
  "settings": {
    "LSP": {
      "clangd": {
        "enabled": true
      }
    }
  }
}

LSP configuration

{
  "clients": {
    "clangd": {
      "enabled": false
    }
  }
}

System PATH

  • C:Program Files (x86)Common FilesOracleJavajavapath
  • C:Program FilesSlickEdit Pro 24.0.1win
  • C:Program FilesPython36Scripts
  • C:Program FilesPython36
  • C:Program FilesPython37Scripts
  • C:Program FilesPython37
  • C:Program FilesPython38Scripts
  • C:Program FilesPython38
  • C:Program FilesOculusSupportoculus-runtime
  • C:WINDOWSsystem32
  • C:WINDOWS
  • C:WINDOWSSystem32Wbem
  • C:WINDOWSSystem32WindowsPowerShellv1.0
  • C:WINDOWSSystem32OpenSSH
  • C:Program FilesCMakebin
  • C:Program FilesGitcmd
  • C:Program Files (x86)WinMerge
  • C:Program FilesLLVMbin
  • C:Android
  • C:WindowsSystem32
  • C:Program Files (x86)NVIDIA CorporationPhysXCommon
  • C:Program FilesNVIDIA CorporationNVIDIA NvDLISR
  • C:Program Filesdotnet
  • C:Program Files (x86)Yarnbin
  • C:Program Filesnodejs
  • C:Program FilesMicrosoft SQL Server130ToolsBinn
  • C:Program FilesMicrosoft SQL ServerClient SDKODBC170ToolsBinn
  • C:Program Files (x86)Microsoft SQL Server150DTSBinn
  • C:Gobin
  • C:UsersRobertAppDataLocalMicrosoftWindowsApps
  • C:mingw64bin
  • C:Python27
  • C:Program Filesplatform-tools
  • C:Program Files (x86)Dr. Memorybin
  • C:externPrograms
  • C:Program Files (x86)Microsoft Visual Studio2019CommunityVCToolsMSVC14.24.28314binHostx64x64
  • C:Program Files (x86)Microsoft Visual Studio2019CommunityVCAuxiliaryBuild
  • C:Program Files (x86)FMOD SoundSystemFMOD Studio API Windowsapi
  • C:Program Files (x86)FMOD SoundSystemFMOD Studio API Windowsapistudiolibx64
  • C:UsersRobertAppDataLocalYarnbin
  • C:UsersRobertAppDataRoamingnpm
  • C:UsersRobertgobin

I suppose the issue is related to triggering completion fast. If you wait two seconds or so, you probably won't be able to reproduce?

I played with this for a while and what I can find so far is that ST seems to be requesting completions more than once.

Given a buffer like this:

    mDevice->createev|

and typing enenter, I can sometimes get this sequence of events:

::  -> clangd textDocument/didChange: {'contentChanges': [{'rangeLength': 0, 'range': {'start': {'line': 264, 'character': 21}, 'end': {'line': 264, 'character': 21}}, 'text': 'e'}], 'textDocument': {'version': 497, 'uri': 'file:///Users/raoulwols/dev/tonic/src/ForwardRenderStrategy.cpp'}}
:: --> clangd textDocument/completion(169): {'textDocument': {'uri': 'file:///Users/raoulwols/dev/tonic/src/ForwardRenderStrategy.cpp'}, 'position': {'line': 264, 'character': 22}}
:: <<< clangd 169: {'items': [{'insertTextFormat': 2, 'sortText': '3e97ae13createEvent', 'detail': 'ResultValueType<vk::Event>::type', 'label': ' createEvent(const EventCreateInfo &createInfo) const', 'filterText': 'createEvent', 'insertText': 'createEvent(${1:const EventCreateInfo &createInfo})', 'textEdit': {'newText': 'createEvent(${1:const EventCreateInfo &createInfo})', 'range': {'start': {'character': 13, 'line': 264}, 'end': {'character': 22, 'line': 264}}}, 'kind': 2}, {'insertTextFormat': 2, 'sortText': '3e97ae13createEvent', 'detail': 'Result', 'label': ' createEvent(const vk::EventCreateInfo *pCreateInfo, const vk::AllocationCallbacks *pAllocator, vk::Event *pEvent) const', 'filterText': 'createEvent', 'insertText': 'createEvent(${1:const vk::EventCreateInfo *pCreateInfo}, ${2:const vk::AllocationCallbacks *pAllocator}, ${3:vk::Event *pEvent})', 'textEdit': {'newText': 'createEvent(${1:const vk::EventCreateInfo *pCreateInfo}, ${2:const vk::AllocationCallbacks *pAllocator}, ${3:vk::Event *pEvent})', 'range': {'start': {'character': 13, 'line': 264}, 'end': {'character': 22, 'line': 264}}}, 'kind': 2}, {'insertTextFormat': 2, 'sortText': '3e97ae13createEventUnique', 'detail': 'typename ResultValueType<UniqueHandle<Event, Dispatch> >::type', 'label': ' createEventUnique(const EventCreateInfo &createInfo) const', 'filterText': 'createEventUnique', 'insertText': 'createEventUnique(${1:const EventCreateInfo &createInfo})', 'textEdit': {'newText': 'createEventUnique(${1:const EventCreateInfo &createInfo})', 'range': {'start': {'character': 13, 'line': 264}, 'end': {'character': 22, 'line': 264}}}, 'kind': 2}], 'isIncomplete': False}
::  -> clangd textDocument/didChange: {'contentChanges': [{'rangeLength': 0, 'range': {'start': {'line': 264, 'character': 22}, 'end': {'line': 264, 'character': 22}}, 'text': 'n'}], 'textDocument': {'version': 498, 'uri': 'file:///Users/raoulwols/dev/tonic/src/ForwardRenderStrategy.cpp'}}
:: --> clangd textDocument/completion(170): {'textDocument': {'uri': 'file:///Users/raoulwols/dev/tonic/src/ForwardRenderStrategy.cpp'}, 'position': {'line': 264, 'character': 23}}
::  -> clangd textDocument/didChange: {'contentChanges': [{'rangeLength': 9, 'range': {'start': {'line': 264, 'character': 13}, 'end': {'line': 264, 'character': 22}}, 'text': ''}, {'rangeLength': 0, 'range': {'start': {'line': 264, 'character': 14}, 'end': {'line': 264, 'character': 14}}, 'text': 'createEvent(const EventCreateInfo &createInfo)'}], 'textDocument': {'version': 500, 'uri': 'file:///Users/raoulwols/dev/tonic/src/ForwardRenderStrategy.cpp'}}

which results in a buffer of

    mDevice->ncreateEvent(const EventCreateInfo &createInfo)

(The response to request 170 comes after commit_completion, and is irrelevant / discarded)


Typing enenter more slowly, I can get this sequence of events:

::  -> clangd textDocument/didChange: {'contentChanges': [{'rangeLength': 0, 'range': {'start': {'line': 264, 'character': 21}, 'end': {'line': 264, 'character': 21}}, 'text': 'e'}], 'textDocument': {'version': 459, 'uri': 'file:///Users/raoulwols/dev/tonic/src/ForwardRenderStrategy.cpp'}}
:: --> clangd textDocument/completion(148): {'textDocument': {'uri': 'file:///Users/raoulwols/dev/tonic/src/ForwardRenderStrategy.cpp'}, 'position': {'line': 264, 'character': 22}}
:: <<< clangd 148: {'items': [{'insertTextFormat': 2, 'sortText': '3e97ae13createEvent', 'detail': 'ResultValueType<vk::Event>::type', 'label': ' createEvent(const EventCreateInfo &createInfo) const', 'filterText': 'createEvent', 'insertText': 'createEvent(${1:const EventCreateInfo &createInfo})', 'textEdit': {'newText': 'createEvent(${1:const EventCreateInfo &createInfo})', 'range': {'start': {'character': 13, 'line': 264}, 'end': {'character': 22, 'line': 264}}}, 'kind': 2}, {'insertTextFormat': 2, 'sortText': '3e97ae13createEvent', 'detail': 'Result', 'label': ' createEvent(const vk::EventCreateInfo *pCreateInfo, const vk::AllocationCallbacks *pAllocator, vk::Event *pEvent) const', 'filterText': 'createEvent', 'insertText': 'createEvent(${1:const vk::EventCreateInfo *pCreateInfo}, ${2:const vk::AllocationCallbacks *pAllocator}, ${3:vk::Event *pEvent})', 'textEdit': {'newText': 'createEvent(${1:const vk::EventCreateInfo *pCreateInfo}, ${2:const vk::AllocationCallbacks *pAllocator}, ${3:vk::Event *pEvent})', 'range': {'start': {'character': 13, 'line': 264}, 'end': {'character': 22, 'line': 264}}}, 'kind': 2}, {'insertTextFormat': 2, 'sortText': '3e97ae13createEventUnique', 'detail': 'typename ResultValueType<UniqueHandle<Event, Dispatch> >::type', 'label': ' createEventUnique(const EventCreateInfo &createInfo) const', 'filterText': 'createEventUnique', 'insertText': 'createEventUnique(${1:const EventCreateInfo &createInfo})', 'textEdit': {'newText': 'createEventUnique(${1:const EventCreateInfo &createInfo})', 'range': {'start': {'character': 13, 'line': 264}, 'end': {'character': 22, 'line': 264}}}, 'kind': 2}], 'isIncomplete': False}
::  -> clangd textDocument/didChange: {'contentChanges': [{'rangeLength': 0, 'range': {'start': {'line': 264, 'character': 22}, 'end': {'line': 264, 'character': 22}}, 'text': 'n'}], 'textDocument': {'version': 460, 'uri': 'file:///Users/raoulwols/dev/tonic/src/ForwardRenderStrategy.cpp'}}
::  -> clangd textDocument/didChange: {'contentChanges': [{'rangeLength': 1, 'range': {'start': {'line': 264, 'character': 22}, 'end': {'line': 264, 'character': 23}}, 'text': ''}, {'rangeLength': 9, 'range': {'start': {'line': 264, 'character': 13}, 'end': {'line': 264, 'character': 22}}, 'text': ''}, {'rangeLength': 0, 'range': {'start': {'line': 264, 'character': 13}, 'end': {'line': 264, 'character': 13}}, 'text': 'createEvent(const EventCreateInfo &createInfo)'}], 'textDocument': {'version': 463, 'uri': 'file:///Users/raoulwols/dev/tonic/src/ForwardRenderStrategy.cpp'}}

which results in a buffer of

    mDevice->createEvent(const EventCreateInfo &createInfo)

I guess ST's internal prefix removal logic resets upon every completion request. Which makes sense. But ST should not do a second request in the first place. isIncomplete = false so that's not at play here.

Can't reproduce this one. Neither with intelephense nor with my simple plugin based on @rwols' payloads: https://gist.github.com/rchl/721c69ab2a01794f07a48841828605df

If it's an actual ST bug, we should find a way to reproduce and submit an issue.

I think that the COMPLETION_FLAG_KEEP_PREFIX flag is not working correctly in the later ST builds.
I tried ST 4085 and 4083 and I can reproduce the issue with LSP-elm:

output

Can you post logs? We still don't have a reliable way to reproduce.

here are my logs, that should be simpler to follow. I added 4 print statements,

  1. When sending the completion request.
  2. When receiving the completion response.
  3. When selecting the completion item.
  4. When we notify the server of a change event

This bug only occurs when we select the completion item before we receive the response for the last request.

notify did change
notify did change
notify did change
send completions request 2
receive response 2
notify did change
send completions request 3
selected item {'textEdit': {'newText': 'Image', 'range': {'end': {'line': 0, 'character': 6}, 'start': {'line': 0, 'character': 5}}}, 'kind': 20, 'label': 'Image', 'sortText': 'b_Image'}
receive response 3
notify did change

b4083

If we select the completion item after we receive the last completion response,
everything works as expected.

notify did change
send completions request 4
receive response 4
notify did change
selected item {'textEdit': {'newText': 'Image', 'range': {'end': {'line': 0, 'character': 7}, 'start': {'line': 0, 'character': 5}}}, 'kind': 20, 'label': 'Image', 'sortText': 'b_Image'}  // this is ok, we selected the completion item after we received the last completion response
notify did change

I was thinking LSP logs :).
Are those completions returned with dynamic completions flag?

I can reproduce the issue even without the dynamic flag.

Let me breakdown what I think is going on.

send completions request 2 // ST Sets the KEEP PREFIX - (prefix == 'I')

1|type I|

receive response 2 // received CompletionItems for request 2

1|type I|
       ___________
       | Image
       |

notify did change // continue typing to trigger a new completion request

1|type Ima|
       ___________
       | Image
       |

send completions request 3 // ST Sets the KEEP PREFIX for completions request 3, (prefix == 'Ima')

selected item // but we immediately select the completion item that was received from request 2

    {'textEdit': {'newText': 'Image', 'range': {'end': {'line': 0, 'character': 6}, 'start': {'line': 0, 'character': 5}}}, 'kind': 20, 'label': 'Image', 'sortText': 'b_Image'}

So what happens is the following.
ST leaves the prefix newest prefix (that was set for request 3, but we selected a completion item recieved from request 2),
which in this case is 'Ima' (prefix == 'Ima') which is the wrong prefix for the request 2.
For the request 2 I expect the Keep prefix to be "I".

So ST leaves the prefix "Ima" and we apply the text edit which leaves us with the following state:

1|type Imagema|

receive response 3 // we receive the response for request 3
notify did change

The thing is, only one completion request is normally triggered in such cases - only with dynamic flag completions are requested for each keystroke. If you are getting multiple completion requests without dynamic flag then that's the root issue most likely.

And I'd like to know how to reproduce that so that we can create minimal test case.

only with dynamic flag completions are requested for each keystroke

Even without the dynamic flag, the on_query_completions is called on each keystroke. (which means that we send the completion request on each keystroke).

Correct me if I am wrong, the DYNAMIC_COMPLETIONS is used by ST to update the completion items in the AC popup when ST is already showing the AC popup. (We use it in LSP when isIncomplete is true, so we don't have to hide and show the AC to make the new Completion items visible in the AC popup)

Even without the dynamic flag, the on_query_completions is called on each keystroke. (which means that we send the completion request on each keystroke).

Well, that's not right then. :)

I wonder if this looks any special:

view.settings().get('auto_complete_selector')

If it's not that then probably you are the only one that can figure it out as it's not normal behavior that happens with all files and servers. Maybe some other installed package affects it? Can you reproduce in safe mode with just a bare minimum of packages installed?

I was wrong, I was pretty certain that the on_query_completion was called on each keystroke without the flag. It is not.

only with dynamic flag completions are requested for each keystroke

This here is correct.

Just to clarify: so all your results were with DYNAMIC_COMPLETIONS flag set?

Just to clarify: so all your results were with DYNAMIC_COMPLETIONS flag set?

Yes,

but even if I remove this code, I can still reproduce the issue that you saw in the gif above.

             response_items = response["items"] or []
-            if response.get("isIncomplete", False):
-                flags |= sublime.DYNAMIC_COMPLETIONS

In that case, maybe you can figure out why it's the case.

  • what's the view settings I've asked about before?
  • does it happen on any file?
  • does it happen with any server?
  • does it reproduce in safe mode with minimum number of packages installed?
  • what's the view settings I've asked about before?
>>> view.settings().get('auto_complete_selector')
'meta.tag, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc'
  • does it happen on any file?
    yes I can reproduce it with any elm file. I just need to type really fast and commit the completion. But 90% of the time the AC works correctly... There is this 10% where I can successfully trigger this bug.

  • does it happen with any server?
    I tried with intelephense the example, but I cannot reproduce it. I can only reproduce it with elm right now.

    • does it reproduce in safe mode with minimum number of packages installed?
      Can I even test this in safe mode? For example when I install LSP in ST --safe-mode, don't the LSP dependencies require a reload of st when I do Package Control: Satisfy Dependecies?

view.settings().get('auto_complete_selector')

Sorry, I meant auto_complete_triggers. But probably it's a dead-end anyway.

Can I even test this in safe mode?

I guess it might be tricky. But since you are on Linux it should be pretty easy to test by creating a separate, clean profile (or rename the main one for testing).

I've tried with LSP-elm and can't reproduce here. It doesn't even use isIncomplete: true by default which I had impression it does for you.

The new alpha build 4086 mentions fixes relating to the prefix removal. Perhaps this is now fixed?

I can confirm that it is fixed with ST build 4086

Was this page helpful?
0 / 5 - 0 ratings