<p>I'm almost finishing my open-source language's verifier. It performs parsing and verification, which ensures a set of programs are valid both syntatically and semantically at compile-time. To start with, I've implemented it in C# (.NET Core).</p>
<p>The question is, is what I've usable by some, say, Visual Studio Code extension to provide type hints? I've never made an IDE extension, so I'm worried about how I'll make use of my language analysis made in C#.</p>
<p>The verifier that ensures a set of programs is valid and that derives an AST with semantic symbols attached to them can be used like follows:</p>
<pre class="lang-csharp prettyprint-override"><code>// scripts hold diagnostics and basic source information,
// such as the file path and the source text.
// a script can be either valid or invalidated.
var scripts = gatherSuppliedScripts();

// parse each script with `new Parser(script).parseProgram()`, returning
// either a `Program` node or null.
// if a script is invalid, `parseProgram()` will invalidate it
// and return null.
var programNodes = toDo();

// the `Verifier` can be considered different things: a symbol solver,
// a type checker and a compile-time validator.
// its only public method is `VerifyPrograms(programList)`,
// which will validate the programs and attach symbol to AST nodes.
// in previous versions, I used to attach symbols through a hash map
// (from `Node` to `Symbol`);
// now I've decided to use AST fields instead, named 'SemanticN'.
// for example, the `Expression` node has a `SemanticSymbol` field that holds
// a `Symbol`.
// the verifier does expose the `ModelCore`, which holds
// references to static symbols and interns structural types
// and argumented definitions. every `Symbol` refers back to
// that same `ModelCore`.
var verifier = new Verifier();
verifier.VerifyPrograms(programList);

// note that every node, including `Program`, holds
// a `Span`. a `Span` holds the `Script` and source locations.
</code></pre>
<p>The way I've implemented that parser and verifier is very much like <em>throwaway</em>. You can't call <code>VerifyPrograms(programList)</code> more than once for the same programs; I've not put any such restriction, but it should not work. An expression is not verified more than once if its internal verifier is called, but a statement is different.</p>
<p>My parser is not tolerant.</p>
<p>I guess that if I were to use my language core from an IDE like VS Code I'd have to perform some caching? Would I've to invoke the compiler multiple times everytime you change the program to reflect the user definitions?</p>
<p>So overall, I'm asking if it's fine to re-invoke the compiler whenever the user updates a script in their IDE?</p>

<static-typing><symbol-solving><ide>
Supporting a statically-typed language in an IDE?
<p>The easiest way to provide a meaningful IDE integration for any language these days is to write an LSP server for it. Pretty much any IDE have a support for LSP, including type hints. There is no need to write your own extension for Visual Studio or whatever, as you can reuse the existing LSP support.</p>
<p>In particular, for the Visual Studio Code you can follow <a href="https://code.visualstudio.com/api/language-extensions/language-server-extension-guide" rel="nofollow noreferrer">this tutorial</a>.</p>
<p>For Emacs, you can look at <a href="https://github.com/emacs-lsp/lsp-mode" rel="nofollow noreferrer">this mode</a>.</p>
<p>For neovim, see <a href="https://neovim.io/doc/user/lsp.html" rel="nofollow noreferrer">this</a>.</p>

CC BY-SA 4.0
2023-06-22T20:32:39.127Z
2023-06-23T15:55:51.727Z
2023-06-23T15:55:51.727Z
SK-logic
CC BY-SA 4.0
2023-06-23T16:33:07.690Z
Do you think it'd be normal to re-run the compiler on `didChangeContent` and thus causing all sources to be re-validated?
Hydroper
CC BY-SA 4.0
2023-06-23T16:34:43.940Z
@MatheusDiasdeSouza - `clangd` and other similar LSP implementations do just this, they re-run compiler on the entire translation unit. It's ok, users don't normally notice delay.
SK-logic
CC BY-SA 4.0
2023-06-23T16:36:04.337Z
Nice... that gives me more hope!
Hydroper
# Supporting a statically-typed language in an IDE?
Posted by: username_0 on 2023-06-22
I'm almost finishing my open-source language's verifier. It performs parsing and verification, which ensures a set of programs are valid both syntatically and semantically at compile-time. To start with, I've implemented it in C# (.NET Core).
The question is, is what I've usable by some, say, Visual Studio Code extension to provide type hints? I've never made an IDE extension, so I'm worried about how I'll make use of my language analysis made in C#.
The verifier that ensures a set of programs is valid and that derives an AST with semantic symbols attached to them can be used like follows:
// scripts hold diagnostics and basic source information,
// such as the file path and the source text.
// a script can be either valid or invalidated.
var scripts = gatherSuppliedScripts();

// parse each script with `new Parser(script).parseProgram()`, returning
// either a `Program` node or null.
// if a script is invalid, `parseProgram()` will invalidate it
// and return null.
var programNodes = toDo();

// the `Verifier` can be considered different things: a symbol solver,
// a type checker and a compile-time validator.
// its only public method is `VerifyPrograms(programList)`,
// which will validate the programs and attach symbol to AST nodes.
// in previous versions, I used to attach symbols through a hash map
// (from `Node` to `Symbol`);
// now I've decided to use AST fields instead, named 'SemanticN'.
// for example, the `Expression` node has a `SemanticSymbol` field that holds
// a `Symbol`.
// the verifier does expose the `ModelCore`, which holds
// references to static symbols and interns structural types
// and argumented definitions. every `Symbol` refers back to
// that same `ModelCore`.
var verifier = new Verifier();
verifier.VerifyPrograms(programList);

// note that every node, including `Program`, holds
// a `Span`. a `Span` holds the `Script` and source locations.

The way I've implemented that parser and verifier is very much like throwaway. You can't call VerifyPrograms(programList) more than once for the same programs; I've not put any such restriction, but it should not work. An expression is not verified more than once if its internal verifier is called, but a statement is different.
My parser is not tolerant.
I guess that if I were to use my language core from an IDE like VS Code I'd have to perform some caching? Would I've to invoke the compiler multiple times everytime you change the program to reflect the user definitions?
So overall, I'm asking if it's fine to re-invoke the compiler whenever the user updates a script in their IDE?
**Tags:** static-typing symbol-solving ide
---
## 1 answers
### Answer by username_1 on 2023-06-22. Score: 3 | Accepted answer
The easiest way to provide a meaningful IDE integration for any language these days is to write an LSP server for it. Pretty much any IDE have a support for LSP, including type hints. There is no need to write your own extension for Visual Studio or whatever, as you can reuse the existing LSP support.

In particular, for the Visual Studio Code you can follow [this tutorial](https://code.visualstudio.com/api/language-extensions/language-server-extension-guide).

For Emacs, you can look at [this mode](https://github.com/emacs-lsp/lsp-mode).

For neovim, see [this](https://neovim.io/doc/user/lsp.html).
> **Comments:**
> **username_0** (2023-06-23): Do you think it'd be normal to re-run the compiler on `didChangeContent` and thus causing all sources to be re-validated?  
> **username_1** (2023-06-23): @MatheusDiasdeSouza - `clangd` and other similar LSP implementations do just this, they re-run compiler on the entire translation unit. It's ok, users don't normally notice delay.  
> **username_0** (2023-06-23): Nice... that gives me more hope!  
---
