Skip to content
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

Local LSP server that improves functionality like item completion #122

Merged
merged 41 commits into from
Jan 11, 2019

Conversation

SamuelBrucksch
Copy link
Contributor

@SamuelBrucksch SamuelBrucksch commented Dec 9, 2018

Initial LSP impl with example from MS sample LSP:
https://github.com/Microsoft/vscode-extension-samples/tree/master/lsp-sample

To test:

npm install
npm run compile
press f5 in vscode

Open a new file, and then select openhab as language or save as *.items/rules/...

This will fix #95 when all the work is done.

Signed-off-by: Samuel Brucksch sasliga@freenet.de

Samuel Brucksch added 3 commits December 9, 2018 14:57
Signed-off-by: Samuel Brucksch <sasliga@freenet.de>
Signed-off-by: Samuel Brucksch <sasliga@freenet.de> (github: )
Signed-off-by: Samuel Brucksch <sasliga@freenet.de> (github: )
@SamuelBrucksch
Copy link
Contributor Author

SamuelBrucksch commented Dec 9, 2018

Unfortunately i did not find an easy way to use our local LSP as proxy for the remote LSP without reimplementing the whole LSP protocol. The vscode-languageclient can not run within the server because it requires a module, that can only be used in the client:
https://github.com/Microsoft/vscode-languageserver-node-example/issues/36

My idea was something like this:
vscode extension -> local lsp -> client in local lsp -> remote lsp
However as the languageclient can not run in the server part (see issue from above) i cant follow that idea.

Instead i now run local and remote LSP server in parallel. In this screenshot you can see diagnostics from local and remote LSP. The green underlined part is from local LSP because its all uppercase (just a sample, no real diagnostics yet) and the red underlined parts are from openhab remote LSP:
image

So we still can implement the item completions in out local LSP server, add diagnostics to the one we ge from the remote server and also do all the other stuff in our local LSP like jumpt to reference and so on...

Its not as nice as extending the remote server, but its still better than nothing.

Maybe later when i have more time i can look into how to write an own language client, but for now this should be enough.

Samuel Brucksch and others added 3 commits December 9, 2018 21:11
Signed-off-by: Samuel Brucksch <sasliga@freenet.de> (github: )
Signed-off-by: Samuel Brucksch <sasliga@freenet.de>
Signed-off-by: Samuel Brucksch <sasliga@freenet.de>
@MHerbst
Copy link

MHerbst commented Dec 10, 2018

I will have a closer look at the implementation at the end of the week. It will also be necessary to do some modifications in the remote LSP because it currently announces to many capabilities which leads to context menu function that won't work.

Signed-off-by: Samuel Brucksch <sasliga@freenet.de>
Signed-off-by: Samuel Brucksch <sasliga@freenet.de>
Items are taken from REST API at start and are getting cached in LSP Server. Their values are updated from SSE (/rest/events). When Items are added or removed the cache is updated. So now we have a very responsive completion list.

Signed-off-by: Samuel Brucksch <sasliga@freenet.de>
@SamuelBrucksch
Copy link
Contributor Author

SamuelBrucksch commented Dec 10, 2018

I added items completion now. Its just a proof of concept and i'm not sure if it is very stable. However now we get the items from rest in the beginning, cache them and update them based on SSE. So we also get new items and items that are removed.

Will clean up the code and make it a bit nicer. I'm also open for ideas on how to improve the ItemsCompletion code in the server part.

Signed-off-by: Samuel Brucksch <sasliga@freenet.de>
Signed-off-by: Samuel Brucksch <sasliga@freenet.de>
@SamuelBrucksch SamuelBrucksch changed the title [WIP] Local LSP server that extends and enhances remote LSP server [WIP] Local LSP server that enhances functionality like item completion Dec 11, 2018
@SamuelBrucksch SamuelBrucksch changed the title [WIP] Local LSP server that enhances functionality like item completion [WIP] Local LSP server that improves functionality like item completion Dec 11, 2018
Signed-off-by: Samuel Brucksch sasliga@freenet.de
Signed-off-by: Samuel Brucksch sasliga@freenet.de
Signed-off-by: Samuel Brucksch sasliga@freenet.de
Signed-off-by: Samuel Brucksch sasliga@freenet.de
@SamuelBrucksch
Copy link
Contributor Author

I think i'm currently at a stage that reflects the functionality from before but with much faster completion.

I can either continue on implementing LSP features, or wait for a review and merge and then add new PRs for new features, which would make more sense for working simultaniously on seperate features.

Signed-off-by: Samuel Brucksch sasliga@freenet.de
@SamuelBrucksch
Copy link
Contributor Author

SamuelBrucksch commented Dec 11, 2018

Maybe some remarks on what i did:

  1. i seperated lsp server (server) and extension (client)
  2. extension config is in root package json, {server,client}/package.json only contains dependencies and some meta info
  3. slightly adapted npm scripts, now we have npm run compile that only compiles and npm watch that watches for changes. compilation is done from the project root and not for each module.
  4. started a local and a remote language client to connect to both local and remote LSP server
  5. Added LSP impl
  6. added completion items provider that caches the items and updates them with SSE
  7. added validation provider that validates documents, this is still WIP and does not do anything yet. However its a preparation for future features.

I think thats all. Maybe we need a utils package for code that is used in both modules like IItem.ts and Item.ts. Maybe more will follow.

Signed-off-by: Samuel Brucksch sasliga@freenet.de
Signed-off-by: Samuel Brucksch sasliga@freenet.de
Signed-off-by: Samuel Brucksch sasliga@freenet.de
Signed-off-by: Samuel Brucksch <sasliga@freenet.de>
…g files

Signed-off-by: Samuel Brucksch <sasliga@freenet.de>
…to vscode-lsp

Signed-off-by: Samuel Brucksch <sasliga@freenet.de> (github: SamuelBrucksch)
@SamuelBrucksch
Copy link
Contributor Author

Should i add changelog entries already or is this done seperately? The current changelog would look something like this:

0.5.0 -TBD

Signed-off-by: Samuel Brucksch <sasliga@freenet.de> (github: SamuelBrucksch)
@MHerbst
Copy link

MHerbst commented Dec 26, 2018

There seems to be a problem with outline view. With the test vsix (#122 (comment)) I did not see any outline. After I went back to the marketplace version the outline was OK.

@SamuelBrucksch
Copy link
Contributor Author

SamuelBrucksch commented Dec 26, 2018

Outline works for me (checked in sitemap, rules, items). Seems like outline items are provided by remote LSP so make sure it is enabled to see the outline. At least when i disabled remote lsp no outline was there, but when i enabled it, it was there...

Signed-off-by: Samuel Brucksch <sasliga@freenet.de> (github: SamuelBrucksch)
Signed-off-by: Samuel Brucksch <sasliga@freenet.de> (github: SamuelBrucksch)
@SamuelBrucksch
Copy link
Contributor Author

Latest vsix:
openhab-0.4.1.zip

@SamuelBrucksch SamuelBrucksch changed the title [WIP]Local LSP server that improves functionality like item completion Local LSP server that improves functionality like item completion Dec 28, 2018
@SamuelBrucksch
Copy link
Contributor Author

Any more comments or reviews?

@SamuelBrucksch
Copy link
Contributor Author

Come on guys, this is important to work on other tasks as well.

@MHerbst
Copy link

MHerbst commented Jan 6, 2019

@SamuelBrucksch @Confectrician My runtime tests were OK. Did not find any problems.
Just one idea (if possible): the context menu for code completion gets all item changes via SSE. But the item view must be manually updated. Would be nice if this could be updated automatically as well.

@SamuelBrucksch
Copy link
Contributor Author

Hi, about the items view: i noticed that as well. I think we can also use the completion items from LSP for that. Behaviour did not change, it was like that from the start so i wanted to do this in a seperate PR later. Not sure ifwe actually need the values in completions at all, i thought about a hover provider that displays the values on hover of an item in code.

@MHerbst
Copy link

MHerbst commented Jan 6, 2019

Not sure ifwe actually need the values in completions at all, i thought about a hover provider that displays the values on hover of an item in code.

In completions completion the item names and an information about the type are sufficient.
Hover with current value would be nice :-)

@Confectrician
Copy link
Collaborator

Hi all,

I finally had some time for (functional) testing and could not recognize any missbehavior for now.
I didn't look at the code yet in detail, but will do so at least for the ts parts.

Sorry for the delay, but we are all doing this in our free time besides work/school/study/whatever.
I know it can be annoying sometimes, but that's one of the compromises open source can bring.

@Confectrician
Copy link
Collaborator

@SamuelBrucksch maybe you can squash your commits and add a sign off now?

@Confectrician
Copy link
Collaborator

Confectrician commented Jan 7, 2019

Also https://app.codacy.com/app/Confectrician/openhab-vscode/pullRequest?prid=2701365 shows some issues.
All of them are located in the js server part and most of them are about quoting style.
Maybe you could have a look at that.
But since it doesnt reduce functionality for now thats not a must have for me.

Edit:
Looking at our .ts files they seem to have single quote used most/all times,
so it would only be consistent to leave them in js single quoted too for now. :)

@SamuelBrucksch
Copy link
Contributor Author

SamuelBrucksch commented Jan 7, 2019

Hi, whats the best way to squash them? I saw rebase -i works or reset soft and then merge --squash, but i guess all of them would result in a git push -f at the end so all the single commits are gone, is that right?

Double quotes for JS does not make much sense as there are also other ways to create strings like

const number = 5
console.log(`Number is ${number}`)

This does not work with double quotes. Also its easier to use quotings and so on in single quotes without disturbing escape characters.

@Confectrician
Copy link
Collaborator

so all thesingle commits are gone

Yep but this doesn't matter in this state.
We are doing squash and merge in openhab repos anyway.
So at the latest when merging, this will be one commit in master.

We can leave it too, its just some cosmeticcal stuff to satisfy pullapprove . 🙂

@Confectrician
Copy link
Collaborator

@MHerbst or @kubawolanin any additional comments?
We can change stuff anyway and from my tests its functional, so i would say lgtm.

@Confectrician
Copy link
Collaborator

Confectrician commented Jan 9, 2019

:shipit:

Approved with PullApprove


/*
documentSaved (event) {
// TODO can be used for format on save feature
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are minor things but since we're using version control, let's avoid checking in a commented out code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, i just left it there so we can see faster how it works when we enhance LSP. But i can remove it, no problem.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove them too.
Those are just empty functions.

We could open an issue instead, which reminds us that these functions (names written down) could be used later.

Signed-off-by: Samuel Brucksch <sasliga@freenet.de> (github: )
@SamuelBrucksch
Copy link
Contributor Author

I removed the commented code. Do you still want me to squash everything even if is squashed anyways?

@kubawolanin
Copy link
Collaborator

kubawolanin commented Jan 11, 2019

I removed the commented code.

Perfect, thanks!

Do you still want me to squash everything even if is squashed anyways?

I think we're good here, since you've signed off your first comment and committed all code with one git user :-)
Let's get this on master now!

Thank you for your work.

@kubawolanin kubawolanin merged commit 91e7770 into openhab:master Jan 11, 2019
@SamuelBrucksch SamuelBrucksch deleted the vscode-lsp branch January 11, 2019 10:14
@SamuelBrucksch
Copy link
Contributor Author

Yay! Thanks for reviewing. Now i will add a lot more PRs ;).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autocompletion/syntax checking extremely slow/unusable
4 participants