d2-vscode icon indicating copy to clipboard operation
d2-vscode copied to clipboard

support autocompletion/hinting

Open Morriz opened this issue 1 year ago • 6 comments

Like the title says. I don't know how that is done best for extensions, but I've seen it done via published openapi definitions.

Morriz avatar Feb 26 '23 13:02 Morriz

i'm not sure either but i always thought we'd need an LSP for it (which we'll definitely want to do). like when the editor is trying to autocomplete a "shapes" value, i don't think it'd be able to know to pull from list of shape values for autocomplete with just openapi definitions.

alixander avatar Feb 26 '23 15:02 alixander

Yeah, nested structures could not be mapped with openapi alone I guess. But I guess it is not rocket science to set up a language server. Probably tedious work.

Morriz avatar Feb 26 '23 18:02 Morriz

yeup, i'll leave this open as it eventually will be vscode task, but we have one for LSP in d2: https://github.com/terrastruct/d2/issues/104

alixander avatar Feb 26 '23 18:02 alixander

When I have time, I'll setup a branch that has the framework for an LSP on the client side. The hard part is going to be the "error tolerant parser" on the server side :)

https://code.visualstudio.com/api/language-extensions/language-server-extension-guide

BarryNolte avatar Feb 26 '23 18:02 BarryNolte

@alixander and @gavin-ts

I have branches in both D2 and D2-VSCODE called LanguageServer that have a working language server. Please check them out. Have the following working:

  1. Errors shown without a preview being created
  2. Import links can be opened, "foo: @BarryNolte " will underline "barrynolte" and allow for a ctrl+click to open "barrynolte.d2".
  3. Rename works, so if you have multiple "x: ...", "x.style...", etc, you can rename "x" and and have it change everywhere.
  4. Find All References works.

Check it out.

I'll try to work on autocomplete for styles if I can figure out what to trigger it on.

BarryNolte avatar Jul 07 '23 23:07 BarryNolte

So these would be the 2 PRs right? We can create these to review/work on

https://github.com/terrastruct/d2/compare/master...BarryNolte:d2:LanguageServer

https://github.com/terrastruct/d2-vscode/compare/master...BarryNolte:d2-vscode:LanguageServer

gavin-ts avatar Jul 17 '23 18:07 gavin-ts