Closed tajmone closed 3 years ago
add a new "Editors Support" category in the repository Discussions, and move therein Discussion #7
Done
Sublime PML will only suggest auto-completions for attributes that are pertinent to a given tag
Awesome!
worth sharing them in the repository Discussions, for the benefits of future contributors
Yes, absolutely.
create a thread on the PML Language Server
I've added category "Language Server" to Discussions
Could you please add a new "Editors Support" category in the repository Discussions, and move therein Discussion #7?
Since editors/IDEs support is an important topic, it might worth dedicating to it its own category, and I was thinking of publishing some posts covering topics like scopes naming and strategies for PML syntaxes, where I wanted to share my experience from the Sublime PML package and the tricks I've learned, which can be useful for anyone creating a PML syntax plug-in in any modern editor based on TextMate grammars.
E.g. I've finally managed to come up with a smart and maintainable system to properly handle node attributes so that Sublime PML will only suggest auto-completions for attributes that are pertinent to a given tag, and only when the cursor is right after the opening node tag, or after another attribute definition — i.e. the syntax is now able to define exactly where tags attributes can go, with awareness of
\
for line continuations extending the valid insertion area, and that attributes completions suggestions should end at the first EOL or after encountering text which is not an attribute definition. It took me some trial and error to achieve this, but finally I've managed to come up with a single syntax context which is shared by all nodes, which makes maintenance much easier.The real trick was to allow the syntax to highlight attributes regardless of whether they are supported by a tag, but restrict completions suggestions only to valid attributes for any tags. This satisfies the criteria of an error-tolerant syntax, and at the same time provides an enhanced editing experience through context-aware completions.
Now that this mechanism is in place, it's just a matter of implementing the remaining tags, attributes and completions — this system even catches unimplemented tags and attributes via (temporary) fallback node/attributes catch-all definitions, which makes the syntax immediately usable in production, even if incomplete.
I believe that the lessons learned here can also apply to other editors that use TextMate-like grammars (e.g. VSCode and Atom), and possibly even apply to Language Servers in some degree. So it might be worth sharing them in the repository Discussions, for the benefits of future contributors — we might also get useful feedback on how to improve this approach.
Creating editor packages can often be confusing, especially when it comes to semantic scoping and choosing appropriate scope names for a syntax like PML (which doesn't fit the paradigm of languages like C, Java, Python, etc., around which these scope naming conventions were designed). Many developers focus only on the syntax highlighting aspect, which is merely aesthetic, but the real power of scopes is their ability to enable/disable various plug-in features according to context: auto-completions, symbols indexing, key-bound actions/macros, etc., which can all be implemented smartly, providing a very smooth editing experience where the syntax is tuned to editing needs.
I'd also like to create a thread on the PML Language Server, where to share links on useful articles and tools, and general thoughts, because a PML Lang Server is definitely the ultimate goal in terms of editors support (albeit still faraway).
It's always nice to have quick access to links and past discussion on such topics.