GithubHelp home page GithubHelp logo

Comments (16)

wylieconlon avatar wylieconlon commented on July 16, 2024 2

I've actually been working on supporting the full language server protocol in CodeMirror for the last month, and you can try many of the methods here: https://github.com/wylieconlon/lsp-editor-adapter

The biggest finding I've had is that Monaco does not fully use the Language Server Protocol when talking to a Service Worker, instead it's using what it calls a "language provider" which is an interface defined here: https://microsoft.github.io/monaco-editor/api/modules/monaco.languages.html

This interface is loosely inspired by the LSP, but is not the same. I can see CodeMirror using the same kind of interface which would allow the implementation of IDE features, regardless of whether they are implemented in-browser or on a server somewhere.

I also found that there are some undocumented requirements of the LSP, such as each document having a file:/// URI, which make it hard to translate to a browser context. For the project I linked above, I found that running on an actual server is a requirement.

from dev.

marijnh avatar marijnh commented on July 16, 2024 1

In the current CodeMirror, that (called 'anyword hint') is just a special case of the general highlighter, which scans the document for matching words.

So whichever way we'd go, we'd want to set up the functionality for collecting and displaying the hints in a generic way, so that you can plug in both something like this and a hyper-advanced code analysis engine.

from dev.

curran avatar curran commented on July 16, 2024 1

With the advancements of Lezer, whole new worlds of autocomplete opportunities may open up.

Really looking forward to seeing how this autocomplete framework turns out!

from dev.

zikaari avatar zikaari commented on July 16, 2024

You might call it overkill, but perhaps could be a step in the right direction. I think there's a tonne we can learn from VSCode (monaco-editor). One of them is LSP (Language Server Protocol) specification. Which I think they defined and is now being used by few other tools.

LSP Specification | AutoCompletion

Now unlike their setup where Language "Server" runs as a separate process, CodeMirror can have WebWorkers if the user desires so[1]. Editor changes can be synced with worker effciently using text-store which is cache based text container that does micro-edits (replace/insert/remove) efficiently.

[1] This is why I chose CodeMirror over monaco-editor. Latter comes with so much stuff built-in, that it uses has to use it own AMD loader in the page. Creating/Overriding global require variable. The worst part is that monaco-editor "manages" when to create/destroy language service WebWorkers thus purging the entire AST a worker might have created for itself.

Love CodeMirror for its modularity.

from dev.

marijnh avatar marijnh commented on July 16, 2024

Seeing whether it's feasible to communicate with language servers would be interesting—I expect there are some issues, like most of them not being written in JavaScript or easily runnable in a web worker, but maybe others have had the same problem and, I don't know, compiled such a server to WebAssembly or something.

Such a connection could act like just another source of completions that our completion UI could query.

from dev.

zikaari avatar zikaari commented on July 16, 2024

Exactly!

I think we shouldn't be concerned about how (typeof tech/backend) to write a language server/service. But more so being compliant with a standard as a client/frontend.

If we stick with that spec, a wrapper/shim around a language service will be only thing required to bridge to different technologies[1], if they are tooooo far apart. Re-writing code just because API calls are different won't be necessary. ICompletionProvider will remain as ICompletionProvider and getCompletionItems will remain as such, so on and so forth.

[1] And that boils down to "modularity" of CodeMirror. Allowing users to plug some wires here and there and get things going, unlike being "locked-down" like monaco-editor.

from dev.

futurist avatar futurist commented on July 16, 2024

For monaco users, It's excellent if can use existing Language syntax definition for getCompletionItems to extract syntax token and provide completions base on the context of input, or provide a way to convert the counterpart into CM syntax token completely (aka need little hack to do the translations)

https://microsoft.github.io/monaco-editor/monarch.html

from dev.

marijnh avatar marijnh commented on July 16, 2024

Nice work. Too bad that LSP isn't generic enough to fit a browser context without modification, but I guess that was to be expected.

from dev.

felipeochoa avatar felipeochoa commented on July 16, 2024

Here's some prior-art that might help for inspiration. Given Emacs has some similar constraints as a browser, could be a useful reference. It supports sync and async completions and is relatively modern (by Emacs standards)

https://github.com/company-mode/company-mode/wiki/Writing-backends

from dev.

curran avatar curran commented on July 16, 2024

What if the autocomplete feature was really simple and JS only? At extension construction time, the API could accept an async function that takes as input the partially completed word, and returns a promise that resolves to an array of strings (the autocomplete suggestions). The autocomplete extension could take care of rendering the selection list and implementing and suggestion selection interactions (arrow keys and enter I suppose).

Integration with various backends or standards seems out of scope for the first layer of an autocomplete framework. IMO the first layer should expose an extremely simple API, then other layers can be built on top of that. Thoughts?

from dev.

marijnh avatar marijnh commented on July 16, 2024

Having a standardized interface for completion sources, which multiple completion UIs can use, is definitely a good idea. It'd have to be a bit more complicated than word → word[], though — not all completions work on words, and many need further context (possibly the state of some on-line code analysis tool) to compute their result.

from dev.

curran avatar curran commented on July 16, 2024

What would it take to get something on the simpler side working, like Vim's autocomplete?
image
This is just word → word[], where the resulting words are words seen by the editor in the current session.

This feels like a subset of the functionality we'd ultimately want for the autocompletion framework, and may generate a useful strawman to start from, which can later be modified to handle various complexities and provide ways to hook into external code analysis tools.

from dev.

arguiot avatar arguiot commented on July 16, 2024

Having such UI would be great, but there should be an API to customize this UI. Like a callback being fired each time the suggestion list changes (basically each time an input is detected)

from dev.

firecrackerz avatar firecrackerz commented on July 16, 2024

only vscode-languageserver-protocol is enough, there is no need to implement vscode-ws-jsonrpc that part user can implement it by themselves.

from dev.

satishbabariya avatar satishbabariya commented on July 16, 2024

I would like codemirror.next to have pluggable minimal Auto-Complete Suggestions and languageserver-protocol as an extension.

from dev.

marijnh avatar marijnh commented on July 16, 2024

This is in good shape now. I've opened #226 and #227 for open issues.

from dev.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.