sublimelsp / LSP-json

Schema validation/completions for your JSON and Sublime files
MIT License
75 stars 10 forks source link

Suggestion: intercept auto-complete request from the server and don't show it #69

Closed rwols closed 3 years ago

rwols commented 4 years ago

This server suggests to show the auto-complete when it auto-completes to a snippet like "foo": {$1}. Right now we dutifully show the auto-complete in LSP/plugin/execute_command.py. We should instead not show it because it goes against the flow of writing json in Sublime Text.

When I have my cursor in-between { and } I expect that when I press enter, ST runs a macro that should position it like

"foo": {
    |
}

what instead now happens is that the AC is shown. This prevents the macro from running.

rwols commented 4 years ago

Okay, it's only bad when the snippet is either

"foo": {$1}

or

"foo": [$1]

when the snippet is of the form

"foo": $1

then it would actually be a UX improvement to show the auto-complete.

rchl commented 4 years ago

Do you have any existing property that I could test it on?

rchl commented 3 years ago

Did you mean that the server triggers editor.action.triggerSuggest? I don't see it triggering it in those cases:

    {
      "documentation": {
        "kind": "markdown",
        "value": "A dictionary of code action identifiers that should be triggered on save.\n\nCode action identifiers are not officially standardized so refer to specific server's documentation on what is supported but `source.fixAll` is commonly used to apply fix-on-save code actions.\n\nThis option is also supported in syntax-specific settings and/or in the `\"settings\"` section of project files. Settings from all those places will be merged and more specific (syntax and project) settings will override less specific (from LSP or Sublime settings).\n\nOnly \"source.*\" actions are supported."
      },
      "filterText": "\"lsp_code_actions_on_save\"",
      "insertText": "\"lsp_code_actions_on_save\": {$1},",
      "insertTextFormat": 2,
      "kind": 10,
      "label": "lsp_code_actions_on_save",
      "textEdit": {
        "newText": "\"lsp_code_actions_on_save\": {$1},",
        "range": {
          "end": {
            "character": 24,
            "line": 16
          },
          "start": {
            "character": 1,
            "line": 16
          }
        }
      }
    },
    {
      "documentation": {
        "kind": "markdown",
        "value": "Disable language server capabilities."
      },
      "filterText": "\"disabled_capabilities\"",
      "insertText": "\"disabled_capabilities\": [$1],",
      "insertTextFormat": 2,
      "kind": 10,
      "label": "disabled_capabilities",
      "textEdit": {
        "newText": "\"disabled_capabilities\": [$1],",
        "range": {
          "end": {
            "character": 24,
            "line": 16
          },
          "start": {
            "character": 1,
            "line": 16
          }
        }
      }
    },

It does trigger it in this case:

    {
      "command": {
        "command": "editor.action.triggerSuggest",
        "title": "Suggest"
      },
      "documentation": {
        "kind": "markdown",
        "value": "Highlighting style of `\"highlights\"`: accentuating nearby text entities that are related to the one under your cursor. When set to the empty string (`\"\"`), no diagnostics are shown in-line."
      },
      "filterText": "\"document_highlight_style\"",
      "insertText": "\"document_highlight_style\": $1,",
      "insertTextFormat": 2,
      "kind": 10,
      "label": "document_highlight_style",
      "textEdit": {
        "newText": "\"document_highlight_style\": $1,",
        "range": {
          "end": {
            "character": 24,
            "line": 16
          },
          "start": {
            "character": 1,
            "line": 16
          }
        }
      }
    },

Or did you mean that the selector is too broad and triggers the autocomplete?

rwols commented 3 years ago

No I meant the editor.action.triggerSuggest command. But it’s ignored now so I think this can be closed.

rchl commented 3 years ago

Have also merged and released https://github.com/sublimelsp/LSP-json/pull/79 now which gets rid of the error message box triggered when the server triggered editor.action.triggerSuggest.