Skip to content

d2-vscode LanguageServerChanges - #1534

Merged
gavin-ts merged 4 commits into
d2lang:masterfrom
BarryNolte:LanguageServer
Nov 28, 2023
Merged

d2-vscode LanguageServerChanges#1534
gavin-ts merged 4 commits into
d2lang:masterfrom
BarryNolte:LanguageServer

Conversation

@BarryNolte

@BarryNolte BarryNolte commented Aug 4, 2023

Copy link
Copy Markdown
Contributor

These changes are for the language server in d2-vscode.

When the D2_LSP_MODE environment variable is set, the d2 cli will read the d2 file, produce the ast (and possible errors), convert it to JSON, print it out to stdout, then terminate. This was done this way to keep the changes to the d2 cli code to a minimum.

PR for d2-vscode to come after this is accepted

@gavin-ts @alixander

These changes are for the language server in d2-vscode.

When the D2_LSP_MODE environment variable is set, the
d2 cli will read the d2 file, produce the ast (and possible
errors), convert it to JSON, print it out to stdout,
then terminate.  This was done this way to keep the
changes to the d2 cli code to a minimum.

PR for d2-vscode to come after this is accepted
@alixander

Copy link
Copy Markdown
Collaborator

AFAIK, LSPs should be daemon processes, otherwise it'd have to reindex each call or load an index from disk, both of which seem too slow for autocomplete. I haven't looked too much into LSPs, is this just for testing or the beginning of a true LSP effort? @BarryNolte

@BarryNolte

BarryNolte commented Aug 5, 2023

Copy link
Copy Markdown
Contributor Author

I should have made this clearer. This is the only change needed in the d2 cli code. I wasn't going to duplicate the language parsing in typescript, I'm too old for that, so I'm leveraging the de facto parser to get the AST for the language server. I have a working and 99% complete language server (yes, it runs as a deamon) in the d2-vscode/LanguageServer branch, I'm taking the weekend to squash the last couple bugs, and I wanted this in first.

As far as speed, it appears to be good. Running d2 to get the AST on my machine (which is slow) takes ~50ms, and my analysis of the resultant JSON version of the AST is ~1ms.

Comment thread d2compiler/compile.go Outdated
Co-authored-by: gavin-ts <85081687+gavin-ts@users.noreply.github.com>
Comment thread d2compiler/compile.go Outdated

@gavin-ts gavin-ts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can update where this code is in a follow up

@BarryNolte

Copy link
Copy Markdown
Contributor Author

Sounds good. Thanks!

@gavin-ts
gavin-ts merged commit 6865181 into d2lang:master Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants