Sublime Forum

Sublime-completions not working with custom sublime-syntax

#1

Hello :slight_smile:

I have those files:

test.sublime-completions

{
	"scope": "text.test testitem",
	"completions": [
		{
			"trigger": "test",
			"contents": "test_test_test"
		}
	]
}

test.sublime-settings

{
	"auto_complete": true
}

test.sublime-syntax

%YAML 1.2
---
name: test
file_extesions:
  - test
scope: text.test
contexts:
  main:
    - match: \btesta .*? testb\b
      scope: testitem

Why autocompletion does not work in this file?

test.test

df g

testa test testb

gfhgfh

If I understand correctly, completion list should popup when im writting word “test” when cursor is between words “testa” and “testb”.

What I’m doing wrong?

0 Likes

#2

The auto_complete setting controls whether auto-completion is enabled or not, but this goes hand in hand with the auto_complete_selector setting as well.

The default for that setting is this:

// Controls what scopes auto complete will be triggered in
"auto_complete_selector": "meta.tag - punctuation.definition.tag.begin, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc",

This says that by default auto-completion happens inside of tags and in source type files (with restrictions placed on each one). However, in your syntax the top level scope is text and not source, and since text isn’t in the setting, it doesn’t appear automatically.

As a consequence the auto-complete popup won’t appear unless it’s manually triggered.

You can add a customized version of the auto_complete_selector setting that overrides the default by using a test.sublime-settings file such as:

{
    "auto_complete": true,
    "auto_complete_selector": "text.test"
}

Note that If you’re developing something like this for more widespread use and not just for your own personal use, it may be a good idea to skip the auto_complete setting here and just keep the selector; with that setting in there you’re essentially forcing auto-complete to be turned on by default in files of this type, which may go against the wishes of whoever is using your package.

1 Like