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

fix bug in 'switchImplIntf': #254

Merged
merged 2 commits into from
Oct 6, 2020
Merged

Conversation

ulugbekna
Copy link
Collaborator

@ulugbekna ulugbekna commented Oct 2, 2020

Fixes ocamllabs/vscode-ocaml-platform#382:

one couldn't switch from a new file that's not saved on disk
(in vscode it's a file with URI scheme 'untitled')

The previous switching logic depended on document store, which only
knows files that were opened with a 'textDocument/didOpen'
notification. VS Code doesn't send such notifications for unsaved files,
hence the bug. Now switching handled file URIs directly without
dependence on document store, which works for any 'switchImplIntf'
request with a valid URI.

Note: handling of URIs is brittle as is the current URI module. I would strongly be in favor of adding a vendored dep ocaml-uri.

TODO:

  • add proper error handling using result
  • add tests for 'untitled' scheme (without loss of generality for other schemes that follow URI conventions of scheme:/path)

@ulugbekna ulugbekna marked this pull request as draft October 2, 2020 20:26
let possible_filepath = Uri.to_path file_uri in
if possible_filepath = Uri.to_string file_uri then
(* remove URI scheme *)
String.split ~on:':' possible_filepath |> List.tl |> List.hd
Copy link
Member

Choose a reason for hiding this comment

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

How about just:

match String.split with
| _ :: x :: _ - >x
| _ -> assert false

@rgrinberg
Copy link
Member

VS Code doesn't send such notifications for unsaved files,
hence the bug.

Does that mean there's no lsp assistance until the file is saved?

@ulugbekna
Copy link
Collaborator Author

VS Code doesn't send such notifications for unsaved files,
hence the bug.

Does that mean there's no lsp assistance until the file is saved?

Yes; extension understands that's an OCaml file but we miss ocamllsp support for that file. We could artificially send didOpen notif when that unsaved file is created, but we'd have to handle cases: what happens when it's saved, what happens when it's closed without saving, can merlin handle files with non file URIs, etc.

@rgrinberg
Copy link
Member

Yes; extension understands that's an OCaml file but we miss ocamllsp support for that file. We could artificially send didOpen notif when that unsaved file is created, but we'd have to handle cases: what happens when it's saved, what happens when it's closed without saving, can merlin handle files with non file URIs, etc.

Nah, there's no need. I was just curious if this was indeed the case. It seems like a flaw in LSP itself and we shouldn't bother patching over it.

@ulugbekna ulugbekna marked this pull request as ready for review October 6, 2020 21:36
  one couldn't switch from a new file that's not saved on disk
  (in vscode it's a file with URI scheme 'untitled')

  The previous switching logic depended on document store, which only
  knows files that were opened with a 'textDocument/didOpen'
  notification. VS Code doesn't send such notifications for unsaved files,
  hence the bug. Now switching handled file URIs directly without
  dependence on document store, which works for any 'switchImplIntf'
  request with a valid URI.
* add a test to switch from file uri with non-file scheme
@rgrinberg rgrinberg merged commit 2d1e7c0 into ocaml:master Oct 6, 2020
rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Oct 14, 2020
CHANGES:

## Features

- Implement a command to switch between module interfaces and implementations
  (ocaml/ocaml-lsp#254)

## Fixes

- Do not crash on invalid positions (ocaml/ocaml-lsp#248)

- add missing record fields to list of completions (ocaml/ocaml-lsp#253)

- do not offer `destruct` as a code action in interface files (ocaml/ocaml-lsp#255)
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.

Switching implementation/interface for unsaved file fails silently.
2 participants