-
Notifications
You must be signed in to change notification settings - Fork 89
langserver: TextEdits computed from diff for gofmt #83
Conversation
bc5ef99
to
33d6460
Compare
I've tested this functionality a bunch. However, I've disabled the formatting test and I need to file an issue on vscode for the deletion of trailing whitespace. The reason I disabled the test is I need to make some changes to the test harness to make it possible to test, but I have done plenty of manual testing in vscode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat! No complaints from me. Sorry for the late review!
@slimsag no worries, I've been wanting to adjust the implementation anyways to avoid the vscode bug. |
@slimsag This PR is still very close to completion. The issue I was experiencing with it was around trailing whitespace and removing it. I don't think I'll be able to finish it off soon though, if you are interested in looking at it? |
@keegancsmith @slimsag Any updates on this? One update from VS Code is that, now even if you send the original edit that deletes everything and adds the new output, VS Code will take care of calculating the minimal edits required. |
Great, yeah this PR has been on the backburner a long time (more than a year)! I'll see how it works in vscode today, previously I was running into a bug around text edits and trailing whitespace in a file. One potential issue of enabling this functionality is that it just uses gofmt. However, I assume some users want goreturns or gimports instead? |
@ramya-rao-a the current behaviour of the go-langserver is to send an edit which deleted everything followed up by inserting the formatted code. So it seems that is good for you? This PR is about sending minimal edits ourselves. |
Before this commit we would send an edit which deleted everything followed up by inserting the formatted code. This lead to a bad experience in vscode. This change implemented a more minimal number of TextEdits by using difflib. The behaviour now matches the behaviour of vscode-go.
33d6460
to
87598ad
Compare
Just tried this again, and getting some errors. I added three empty lines then formatted and got these trace logs. Likely bugs in our implementation
|
Yes, we should come up with a good model of sending configurations over to the LS The choice of formatting tool is one |
* fix uri handling for windows the main problem was that some parts of the code converted the path to lower case and others just passed on the path as it was. e.g didOpen/didChange messages just used the path whereas hover used the lower case path to read the file, so it never read the changed file from the overlay cache! * correctly apply changes in textDocument/didChange to the cached file * fix formatting + some simple tests * add a focus prop to the langserver tests to easily run a single case * fix complete replace of code in didChange handler * remove unnecessary focus prop
Is there anything left here that prevents this from being merged? Looking at the linked issues above it might improve things :) |
I can have a look at the merge conflicts later today if you want :) |
This is a bad merge! Committing since I don't have time to finish off. Conflicts: * langserver/config.go * langserver/handler.go * langserver/integration_test.go * main.go
@keegancsmith here is a patch.txt to fix this branch :) |
I look forward to the changes!! May I know if we will have the change in master by this week? |
Apologies I meant to get to this this week. I have scheduled some time on Tuesday to tackle this. |
@keegancsmith Thank you very much!! |
Before this commit we would send an edit which deleted everything followed up by
inserting the formatted code. This lead to a bad experience in vscode. This
change implemented a more minimal number of TextEdits by using difflib. The
behaviour now matches the behaviour of vscode-go.
WIP Known Issues
Fixes #76