keymanapp / keyman

Keyman cross platform input methods system running on Android, iOS, Linux, macOS, Windows and mobile and desktop web
https://keyman.com/
Other
382 stars 107 forks source link

feat(developer): Keyman-language LSP (to gain auto-complete, etc) #9370

Open jahorton opened 12 months ago

jahorton commented 12 months ago

Since the idea happened to come up in a meeting earlier today, my interest was a bit piqued and I did some quick searching / research.

For the uninitiated: language server protocol. This is a programming-related technology that, when implemented for a language, allows compatible text editors to integrate Intellisense, code-completion, code-definition hotlinking, etc for it. So, implementing this for the Keyman language would allow us to gain these features for keyboard coding! (Our text-editing engine dependency is LSP-compatible.)

For starters: https://microsoft.github.io/language-server-protocol/

That site pretty much has the spec and lots of links to resources for development of language-server protocols. No clear guide that I could quickly find, but there are some parts that serve to ease you into some of the design and such, at least. There's noted use of "JSON_RPC" for cross-platform comms, and the protocol design seems to have been spearheaded by MS to work with VS Code... with noted contribution from other open-source communities. So... TS is likely a pretty good language for working with this stuff. Conveniently... we've been putting Keyman Developer's compilers into TS lately via the 🗜 PR chain as part of #8954 and possibly before.

Searching through the resources and links, one thing in particular stands out:

https://github.com/langium/langium/tree/main/packages/langium-vscode/src/language-server

It's an open source project (main site: https://langium.org/) that's essentially an SDK for parser, compiler, etc development based in TS... one component of which ties into automatic creation/fueling of LSPs. The link above is to the folder where the main interfacing types for their implementation of the feature exists. Other components of possible relevance exist in other (sibling & parent) folders in that repo.

Of note: MIT licensed, in TS. If nothing else, it'd probably make a valuable reference, and the licensing is very permissive.

Obviously, this isn't the simplest thing to pick up and instantly implement... but since I've gone ahead and found these resources, I figured "why not at least document it?"

mcdurdin commented 3 months ago

https://github.com/github-linguist/linguist/blob/master/CONTRIBUTING.md would be valuable to do alongside this. I think we are close to meeting their requirements for popularity -- certainly there are a lot of unrelated repos, excluding forks: https://github.com/search?type=code&q=NOT+is%3Afork+path%3A*.kmn

We could add a heuristic for 'begin.+use' as that matches on every Keyman keyboard and afaict excludes the handful of unrelated .kmn files in GitHub.

Ref https://github.com/github-linguist/linguist/issues/5756 for current guidelines on popularity for linguist.

(Note: will consider this as part of 18.0 development, for both .kmn and LDML .xml)