Scoping, typings, references, autocompletion structure guidance #856
Replies: 3 comments 15 replies
-
Hey @kristiannotari,
You can always do it like the linker does.
Since every cross reference has a special cross reference type, we don't want to have all objects in scope which are visible in the index, but only those which fit the cross reference type. That's why we apply a filtering there.
This is kind of a weird requirement, since normal language don't work that way. If a nested element is visible to a certain scope (i.e. in your case the root scope which contains the
Yes, that's what I would have recommended 👍
In advance compared to what? A code generator? Yes, the validator is usually always the right place to add these checks when you have a language which could contain semantic errors. There's no other intended way to make users aware of semantic errors in their documents other than the validator infrastructure. The Lox language implementation does the same. Bonus Question: Not really, or at least nothing that Langium provides as a builtin feature. To debug the scoping at a certain position in the document, I usually just run the code completion via |
Beta Was this translation helpful? Give feedback.
-
Hello @kristiannotari , Here's some things I found helpful - I'll defer to the Langium team for deep technical advice, but this is what I use to try and understand what's going on under the hood. DISCLAIMER: IMHO The best resource by far is the Langium implementation itself and I treat it as the 'reference implementation' for Langium. Anything provided below is probably 'almost correct'ish but occasionally not'.
I have found the Langium team to be incredibly supportive and helpful. There's certainly a precedent for creating a dedicated thread for your DSL, so I wouldn't hesitate to do so (my thread, older thread). I just try to return the favor by contributing to the project if and where I'm able. One thing I found incredibly helpful for non-specific DSL design questions was the following book (based on Xtext): Implementing Domain-Specific Languages with Xtext and Xtend - Second Edition (L. Bettini 2016). Note: I attempted to follow along with the book using Langium and had relatively decent success - unfortunately, I've been too busy to finish the scoping portion. However, you're free to take a look as there's a pretty large amount of validation examples one would typically need.
I'm a picture person and not a SW dev by trade, so I drew this:
|
Beta Was this translation helpful? Give feedback.
-
How strange, I'll just embed it:
That particular |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
I've already received a lot of help for my DSL regarding builtin library here.
I'm new to both DSL creation and Langium and I'd like to better understand the document lifecycle, and how I should deal with scoping, typing, references and such. I've read the document lifecycle guide but I'm missing how to properly structure my code given my DSL constraints.
I'd like not to bother you all by creating a discussion uniquely to guide me creating my DSL, but I wanted to get a clearer idea on how to structure things in Langium.
Given this DSL example file (limited example, pretty straightforward to read):
and given these requirements:
a1
,a2
, etc) inside them (each entity can refer to its own named values only known at a given point in the file, so for example the second entity block ofA
can access thea1
named value defined earlier)compare
can access every named value from every entity, ignoring entity scopingSolutions/structures/questions I see/have:
ScopeComputation.computeExports
returns an empty arrayScopeComputation.computeLocalScopes
should create aPrecomputedScopes
with a bunch of function definitions ASTDescriptions with the "AST root node" as the containing node and then in theScopeProvider.getScope
how can I get those functions definitions? In theDefaultScopeProvider
there's a "global scope" created with theindexManager.allElements
method, but I can't understand how's that working since it's filtering with theReferenceType
???ScopeComputation.computeLocalScopes
should be scoped under eachentity
definition block node, adding all the named values inside them. Doing so I create N scopes where N is the amount ofentity
definition blocks I encounter, even if repeated for the same entity. How can I then implement in theScopeProvider
the ability to access every named value know UP to the point I am? (example: in the first entityA
definition block I should not seea2
since it's defined later)ScopeProvider
, when retrieving the scope for acompare
node I should get every named value (and function) basically. Should I retrieve the "file global scope" (see point 2) and add to that each precomputed scope from each entity definition block in the entire document/file, going upwards in the ast node from where I am?I'd like to know if my understanding is correct or if I'm mistaken somewhere. Thanks in advance!
EDIT: bonus question: is there some way to visually grasp what's being built by the various "passes" from text to scopes and stuff? Like some diagrams populating based on cursor position in a DSL file or something like that? Cause that would help greatly to see what's being built behind the scene. Or is there another way to properly debug these "internals" without having to rely on editor hints to know what's available in scope?
Beta Was this translation helpful? Give feedback.
All reactions