paulstansifer / unseemly

Macros have types!
http://unseemly.github.io/
MIT License
131 stars 5 forks source link

Language Server #36

Open colelawrence opened 4 years ago

colelawrence commented 4 years ago

Perhaps another open ended question, but in your mind how feasible do you think general editor completion support could be for unseemly?

I have this pipe dream in my mind that a language server / command driven compiler could give you hints about what forms and types are valid for autocompletion by referencing the macro definitions themselves. Thereby ensuring that you only have one core language server that is able to make completions for any range of DSLs within unseemly.

Is that completely crazy to consider at this point? Is it feasible?

Thanks!

paulstansifer commented 4 years ago

I think that an incremental parser should be possible (I don't know much about how suited an Earley parser is for that), and I definitely want to eventually have an LSP plugin. Macro syntax lives in the language grammar itself, so handling macros wouldn't require much work outside the parser.

Completion of variable names and function invocations is probably not much harder than for any other language (once an incremental parser capable of dynamic syntax extensions exists!), but I'm not sure what full-featured completion for macros would look like, given that macros can be "deeply" varadic. For example, in an LSP completion, a completion can offer a finite list of snippets that the user can tab through, but what about a let macro that has n pairs of names and values? I guess, a lot of the time, having exactly one occurrence of each repeat would be good documentation, even if you can't just tab through the snippets.

...actually, I think the solution to this problem is to complete at the syntax level, not at the macro level. If your context looks like let a = 1; b = 2 and you request completion, I could imagine being able to offer two options: ; {$name} = {$expr}; and ; {$expr}. That sort of thing might be sufficient to document a macro if the user remembers how its invocation begins.

(At some point, I think that macros should be able to hint to the pretty-printer how they want to be auto-formatted. While I'm imagining that unicorn, I think it could guide the snippet formatting as well.)

This is looking way ahead, of course. Building an LSP link at all would be a good first step, and maybe it wouldn't be too hard to build a proof-of-concept.