-
Notifications
You must be signed in to change notification settings - Fork 799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make specification more machine-readable #67
Comments
#25 may be related |
I basically was looking for protocol.ts. |
Agree with @gorkem that a machine readable specification should be in JSON Schema since this is more universal. There are quite some tools out there to generate interface files from JSON for different languages. |
JSON schema would be awesome, and also allow to be more specific than TS interfaces. For example, you can apply RegExp constraints to strings. |
An editor will need to have fast response times from a server to be interactive. With upb the backend can be chosen:
The protocol is defined with an schema and is fully machine-readable. |
@vicencb the protocol buffer is about the transport. Since the message header allows to specify a content type we can send binary data if this is necessary due to performance. This issue is about having the specification in a machine readable from. |
Not sure if you want to collect examples of what's difficult to parse here in this issue, but I just came across another one and thought it worth noting.. The response to However this text only appears in the
I really want to avoid too many special cases to make it easier to keep my classes up-to-date, but now I have a regex like |
Another inconsistency found while parsing: Some notifications list their params as |
@DanTup when I started to convert this to JSON schema I used a TS compiler to parse the TS file from https://github.com/Microsoft/vscode-languageserver-node/blob/dbaeumer/464/protocol/src/protocol.ts#L1 which should give the best result. |
@dbaeumer Thanks! That might've been a better thing to parse when I started, though I now have a fairly-complete parser for the spec and it's probably not worth changing. I was just noting inconsistencies I noticed in the hope the official spec might become friendlier for parsing. Out of interest, you say started to convert to JSON schema - is that still in progress? Will it become an official schema? I don't want to mess with the parser too much now it (mostly) works, but switching from a TS-parser-written-in-Dart to something structured would definitely be nice. |
@DanTup it is on hold right now due to other priorities. As always community help is appreciated here. |
Just another vote for JSON-Schema or some sort of protocol.json as core first-class part of the LSP project's spec efforts. I had previously for example utilized https://github.com/Microsoft/vscode-debugadapter-node/blob/master/debugProtocol.json to generate code scaffolds with great success, and was "almost sure something like LSP must have something equivalent --- by now" until just minutes ago. Looks like not-yet.. but should substantially ease the burden on contributors to the ecosystem (client and server implementations written in countless languages) especially when it comes to them keeping up with new versions (swiftly or at-all), supporting multiple versions, remaining motivated to not abandon their client or server implementation, or if that happens easier and swifter springing up of alternative implementations etc. Alternatively the question could be whether the TypeScript project offers-and-supports (or whether it should) some sort of baseline / stable / maintained |
I agree with this and when I last looked into this I was experimenting with converting the d.ts to JSON schema automatically. This would be a great opportunity for the community :-) |
Out of curiosity: Are there any good tools available for this task? Have you encountered any pitfalls with the automatic conversion so far? A little bit off-topic: For the other way around I like using json-schema-to-typescript. |
I've used https://github.com/YousefED/typescript-json-schema with great success for this. We could use that to generate the initial schema, manually optimize it, commit it and then delete the original TypeScript and start generating it from the JSON schema with https://github.com/bcherny/json-schema-to-typescript. |
I've some success to report with:
Here's the whole gist (or binder, if you're into that sort of thing), and the schema as JSON (or YAML). It hasn't been exhaustively tested, but by inspection appears to be fairly thorough. I'd love to see something like this made more official, but will probably keep tinkering with it. 👏 Thanks to @domoritz, for helping me get |
Would love to see JSON schema be the first-class spec as it is with DAP. The fact that the TS and JSON data types don't align perfectly came up in #833 (comment). |
Sounds good! Given there is some precedent with DAP, is the schema...
As a downstream consumer of the spec, all of these properties would be desirable. A canonical representation in YAML, TOML, or some other JSON-data-model-but-not-braces-and-escaped-newlines format with embedded markdown (or commonmark) could fill the bill, be linted/formatted, and remain pretty PR-able. A schema can even include extra, validator-opaque metadata, like |
@bollwyvl DAP does generate the human-readable documentation specification.md using spec-generator. |
Cool, spec-generator looks great!
|
Oh, I see. What's the difference between There's also a bit of a mismatch in casing (for example |
|
If you have problems in Dart with this I suggest that you create one enum instead of two. There is no need that your generated libraries follows this |
Ah, of course!
Ah, gotcha. In that case I'll just make I haven't found any other issues yet, but I'm not quite done. I'll let you know if I do (or if I complete the migration and have no other issues). Thanks! |
OK. I will publish a release today / tomorrow. Updating the meta model is something we can always do. None of the things you reported did actually need a change the specification itself. It was more generation bugs. |
Add to 3.17. The meta model is also reachable via the specification site |
@dbaeumer awesome, thanks! I'm hoping to finish the migration in the next day or so (I think I'm down to the last few issues, but I'm first migrating via the TS version because it'll be much easier to review switching from TS -> metaModel if it's not also the 3.16 -> 3.16 upgrade). Just FYI in case you hadn't noticed:
|
Actually Will remove the upcoming |
Done. |
Why is there a double slash ( |
Don't know. Let me see if I can fix this. |
I tried to fix this, but I was not able to do so. Interestingly it doesn't happen when executing jekyll locally. Does anyone has an idea? |
@dbaeumer I think
Not sure, but could it be related to these two things being mashed together:
In this page it says "Leave off trailing forward slashes when setting url". I don't know if you have anything relying on it that could break if you remove it though 😬 |
@DanTup thanks for the Jekyll tip. Applied and works locally. |
@dbaeumer a few other minor things (let me know if here is not still the best place to report them):
|
Regarding
|
@dbaeumer oh, I see - where is that populated from? In the Markdown version of the spec (and the web version on GH Pages) it looks like this:
|
The truth of source are the TypeScript files defined via this TS project: https://github.com/microsoft/vscode-languageserver-node/blob/fd9bcbdb699d2573ee9c53e580c39be2a315ba11/protocol/src/common/tsconfig.json#L1 |
The correct value is |
I'm not sure I understand. In that repo, the docs for
But in the web version of the spec at https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/ they are complete:
Is one of these generated from the other, or are they maintained separately? Edit: The place I can find the correct text is at https://github.com/microsoft/language-server-protocol/blame/35065fc549a5a3e2183769f37aba98457c8cd490/_specifications/lsp/3.17/general/initialize.md#L190 but it's not clear to me where to fix it so the metamodel has all of that text. |
The TS file in the vscode-languagserver-node repository and the specification published to the Web are currently maintained by hand :-( So fixes for the meta model have to go into https://github.com/microsoft/vscode-languageserver-node I do have plan to auto generate the specification from the meta model, however I am not there yet. |
So before I start making changes - I can make fixes to the docs directly in these TS files like here: And they won't be overwritten (and will be used for meta model, and eventually the website)? (I just want to be sure I don't spend time fixing up something that will be overwritten from another source 😄) |
@dbaeumer some other things I in my diff:
I opened microsoft/vscode-languageserver-node#945 to address some of the typos and truncated docs (I don't believe it addresses any of the above though). |
I created microsoft/vscode-languageserver-node#946 since the work actually has to happen in that repository. |
We just published https://pypi.org/project/lsprotocol/ . It's a Python package containing the various types and messages from LSP based on the programmatic definition. That also means we have code now to read the programmatic definition which could be used by others to generate other code representations. |
It would be very handy if parts of the specification could be read by machines.
This would help developing SDKs for typed languages a lot, as many types can be auto generated.
Besides, there are some inconsistencies in non-normative parts of the specification that could be easily fixed (e.g. interfaces vs exported interfaces,
params
vsparam
).Something like this would be awesome in addition to the existing specification:
(comments removed to keep it short)
What do you think? I can offer to add these additional typescript definitions for all of the about 30 notifications / requests.
The text was updated successfully, but these errors were encountered: