Sublime Forum

Trouble with `auto_complete` settings - how to prevent autocomplete popups in strings and comments? `auto_complete_selector` is not working as expected

#1

I’ve been using Sublime Text for a very long time now, and for the first time I actually want to turn on autocompletion suggestions that are being populated via the LSP plugin. I want them in one situation and one situation only, which is where I am typing a member accessor, i.e. something.member. This is with ST4 build 4126 currently. Which I’m aware is a bit out of date, but I don’t see anything clearly related to this in the release changelog since then. (And I am hesitant to update on this machine because I am getting frequent crashes when reordering tabs on the latest build 4169 on another machine.)

This is what my sublime-settings currently look like for the GDScript language, which I have a LSP running for and configured for use with the ST LSP plugin:

	"auto_complete": true,
	"auto_complete_delay": 500,
	"auto_complete_trailing_spaces": false,
	"auto_complete_use_index": false,
	"auto_complete_selector": "punctuation.accessor - comment - string, variable.other.member - comment - string",

This seems to be mostly working, except that the autocompletion popup is showing up when I type a period . within comments or string literals.

Here’s screenshots showing what I mean, where this occurs both in the middle of a line and at the end of one:

I am using a sublime-syntax file that I adapted from a plugin, so my first thought was that I made a mistake in the scopes there. But I can verify that the scopes are correct, and not any of those given in the auto_complete_selector setting via Tools > Developer > Show Scope Name.

Here’s the relevant parts of my sublime-syntax file:

    - match: \b({{identifier}})(?:(\.)({{identifier}})?)*
      captures:
        1: variable.other.gdscript
        2: punctuation.accessor.gdscript
        3: variable.other.member.gdscript
    - match: (##).*$
      scope: comment.line.documentation.gdscript
      captures:
        1: punctuation.definition.comment.number-sign.gdscript
    - match: (#).*$
      scope: comment.line.number-sign.gdscript
      captures:
        1: punctuation.definition.comment.number-sign.gdscript

What’s going on with this? How can I make the autocompletion popup stop showing up in comments and strings? Why is it showing up in scopes that aren’t included in the selector in the first place?

0 Likes

#2

Ah, of course it’s only after I went to the trouble of making a post about this that I stumbled upon the solution myself.

After adding this additional line with the syntax-specific auto_complete settings, the suggestions show up as expected, not in comments or strings:

"auto_complete_triggers": [],

The auto_complete_selector can also be simplified like so, and behaves the same:

"auto_complete_selector": "punctuation.accessor, variable.other.member",

I do not understand why this was necessary. The default preferences don’t have anything in auto_complete_triggers that seems like it would be triggering those unwanted suggestions. But in any case, my issue is fixed now by overriding auto_complete_triggers with an empty list.

	// Additional situations to trigger auto complete
	"auto_complete_triggers":
	[
		{"selector": "text.html, text.xml", "characters": "<"},
		{"selector": "punctuation.accessor", "rhs_empty": true},
	],
0 Likes