-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
feat: to-pipe command #318
Conversation
lib/next_ls/commands/from_pipe.ex
Outdated
alias GenLSP.Structures.WorkspaceEdit | ||
|
||
defp opts do | ||
Schematic.map(%{ |
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.
Please let me know if you have any feedback for the Schematic library! It can get the job done but it was first built with codegen in mind, so the ergonomics are a little off I think. Curious to hear your thought!
@test_scenarios [ | ||
{"to_list(Map.new)", "Map.new() |> to_list()"}, | ||
{"to_list(a, b, c)", "a |> to_list(b, c)"}, | ||
{"Foo.Bar.baz(foo, bar)", "foo |> Foo.Bar.baz(bar)"}, | ||
{"Foo.Bar.baz(foo, bar, Map.new())", "foo |> Foo.Bar.baz(bar, Map.new())"} | ||
] |
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.
love this 🙌
Looking great at first glance! I'll wait til you mark as ready for review til i do a full... um.. review 😆 |
lib/next_ls/commands/from_pipe.ex
Outdated
end | ||
|
||
def new(opts) do | ||
{:ok, %{text: text, uri: uri, position: position}} = Schematic.unify(opts(), Map.new(opts)) |
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.
Is it okay crashing the server if we get bad arguments, I should probably take care of getting an error from schematic as well.
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.
I was going to suggest wrapping the whole handle_event callback in the NextLS module in a try/rescue, so that we can log an error to the user and not crash the whole server.
You can publish a window/showMessage notification (I think there are examples in the codebase), so that it actually presents an UI notification to the user's editor
lib/next_ls.ex
Outdated
GenLSP.notify(lsp, %GenLSP.Notifications.WindowShowMessage{ | ||
params: %GenLSP.Structures.ShowMessageParams{ | ||
type: GenLSP.Enumerations.MessageType.warning(), | ||
message: "[Next LS] #{command} command has crashed" |
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.
I would also log the exception, and the show message can be [Next LS] #{command} has failed, see the logs for more details
Can you also write a couple of full integration tests? |
Okay, I tested this out and wasn't able to get it to work (after making some changes, I'll push them up on another branch so you can see, I rebased so i don't want to force push to your branch). I think the integration tests will reveal where it breaks. I'll paste some of the errors I was seeing to-pipe errors
from-pipe errors
|
Changes i made: fb33786 |
We can punt it to another PR, but I didn't realize that we can return this command from the code actions request from the client, so it shows up in the little light bulb menu |
I have added the changes from this branch as well |
test/support/utils.ex
Outdated
@@ -114,6 +114,27 @@ defmodule NextLS.Support.Utils do | |||
end | |||
end | |||
|
|||
defmacro assert_opened( |
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.
Not the best name, but I need to notify the server so that it loads the text for a certain URI into the documents assigns. Other things that I could do is to load the files preemptively with the initialization step. Another way would be to just expect the client to send the text as well? I think this is the cleanest though, just a little overhead in the tests.
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.
seems fine, can you rename to did_open
?
and can you actually submit this as a separate PR, and add it to all the tests? then i can merge that and i won't have to approve your CI test runs every time you push
b936332
to
b50d042
Compare
i'll try and review/demo this before the weekend |
Tested this out, seems to break in quite a few cases. I was able to turn trying to do it on with the cursor on case parse_program(parser) do
{ast, %{errors: []}} ->
{:ok, ast}
{ast, %{errors: errors}} ->
{:error, ast, errors}
end
end The error being |
Thanks for testing it out, I'll add those as test scenarios. The first scenario no idea why it didn't work, I'll have to take a look, also I'll do a better job of reporting the errors. |
You can use the error tolerant parser be been building (Spitfire) in Next LS now, so it might make this easier. |
94b3e06
to
bd17ae2
Compare
CleanShot.2024-02-24.at.17.39.17.mp4found a case where it leaves a stray variable above the function it un-pipes |
Also that one was a little odd in that it un-piped the begging of the pipe chain instead of the one under the cursor. I would have expected this more or less Enum.map(
file |> NextLS.ASTHelpers.Variables.list_variable_references({line, col}),
fn {_name, {startl..endl, startc..endc}} ->
[file, startl, endl, startc, endc]
end) I'm not sure if that is enough to stop this from merging, can improve it later |
also putting the cursor here results in the error # 👇
Enum.map(
NextLS.ASTHelpers.Variables.list_variable_references(file, {line, col}),
fn {_name, {startl..endl, startc..endc}} ->
[file, startl, endl, startc, endc]
end
)
|
I'll see if i can't get some time to address those test cases tonight |
I have some local changes but haven't finished them yet, I'll try to get that done tomorrow. |
5392a7d
to
5ba29e5
Compare
36cc9ba
to
231e84f
Compare
Fixing a test and the nix flake and then it'll be mergeable. I decided to include the Sourceror library as it has a lot of functions around positions that I was about to remake. As well as its zipper implementation which is useful |
Also I broke out from-pipe into a second PR |
Co-authored-by: Mitchell Hanberg <[email protected]>
231e84f
to
02051b4
Compare
Closes #55
Aims to add to and from pipe to next-ls