Sublime Forum

Filetype with dynamic syntax

#1

Hi there,

I have a custom file type and I am trying to either write a syntax or a plugin so that I can do things like jump to references/definitions. The filetype contains definitions of named paragraphs, and those paragraphs contain references to the names of other paragraphs.

For example:

* Hello world: This is a paragraph.

* Goodbye world: This is a paragraph that references [[Hello world]].

Paragraphs can be grouped using asterisks, and groups create a local namespace that affects the interpretation of link target, eg:

* Hello world: This is a paragraph that contains a reference to [[local paragraph]].

Local parargaph: This is a local paragraph in the namespace of “Hello world”

Lastly, there is dynamic syntax for writing links, so eg:

* Hello world: This is a paragraph that contains a link to [[the paragraph {{goodbye world}}]], and the double curly braces signify that the target is “goodbye world” and not the full display string “the paragraph goodbye world”.

* Goodbye world: This is a paragraph that references [[Hello world|with a custom display text]].

So, I’d like to have 1) jump to definition, 2) jump to references, 3) symbol search, and ideally 4) completions for link names. However, this filetype has references which require dynamic analysis to resolve. So, I’m wondering if there is a way of writing a plugin in Python that accesses the Sublime syntax features like references and definitions, or whether I should just do everything manually, eg parsing the file, populating the quick panel, moving the cursor, etc.

Thanks for your help!

0 Likes

#2

In the end I did everything manually with quick panels and cursor movements, but I’m curious if there was a better way that made use of Sublime’s built-in syntax functionality. Thanks!

0 Likes

#3

The functionality for the points 1), 2) and 3) should work automatically if the syntax is “good enough”, i.e. if it uses the standard scope names for tokens which are considered a symbol definition and should appear in the symbol list. You can see the scope names, which are used by default for this, in the Default/Symbol List.tmPreferences file (use the “View Package File” command from the command palette to open that file). They are entity.name.function, entity.name.type, entity.name.class, entity.name.enum, entity.name.namespace, entity.name.filename, meta.toc-list.

If you want other scopes to appear in the symbol list, or if these scopes are not really applicable to your language, you can also configure your own scope names for this via a .tmPreferences file, see https://docs.sublimetext.io/reference/symbols.html#defining-symbols.

For the completions, it looks like that static completions from a .sublime-completions file might not be sufficient for your use case. But you could implement them in Python, see https://www.sublimetext.com/docs/completions.html#plugins. The View.find_by_selector (and View.substr) API method could be helpful for that, presuming you gave a special scope to the link and paragraph markup in the syntax.

0 Likes

#4

@jwortmann Thanks so much for your help! Looks very promising

0 Likes