4
$\begingroup$

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?

$\endgroup$
0

1 Answer 1

3
$\begingroup$

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.

For Emacs, you can look at this mode.

For neovim, see this.

$\endgroup$
3
  • $\begingroup$ Do you think it'd be normal to re-run the compiler on didChangeContent and thus causing all sources to be re-validated? $\endgroup$
    – Hydroper
    Jun 23, 2023 at 16:33
  • 1
    $\begingroup$ @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. $\endgroup$
    – SK-logic
    Jun 23, 2023 at 16:34
  • 1
    $\begingroup$ Nice... that gives me more hope! $\endgroup$
    – Hydroper
    Jun 23, 2023 at 16:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .