Skip to content

Commit

Permalink
Fix support for renaming modules (erlang-ls#1199)
Browse files Browse the repository at this point in the history
The textDocument parameter in a TextDocumentEdit must contain a version, even if null (see the OptionalVersionedTextDocumentIdentifier definition from the LSP specification). Without it, some editors (most notably VS Code) would reject the edits
  • Loading branch information
robertoaloi committed Feb 15, 2022
1 parent c371027 commit a24f3e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions apps/els_lsp/src/els_rename_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ workspace_edits(OldUri, [#{kind := module} = POI| _], NewName) ->
, type_application
, behaviour
]),
Changes = [#{ textDocument => #{uri => RefUri}
Changes = [#{ textDocument => #{uri => RefUri, version => null}
, edits => [#{ range => editable_range(RefPOI, module)
, newText => NewName
}]
} || {RefUri, RefPOI} <- RefPOIs],
#{documentChanges =>
[ %% Update -module attribute
#{textDocument => #{uri => OldUri},
#{textDocument => #{uri => OldUri, version => null},
edits => [change(POI, NewName)]
}
%% Rename file
Expand Down
12 changes: 6 additions & 6 deletions apps/els_lsp/test/els_rename_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -233,26 +233,26 @@ rename_module(Config) ->
Expected = [
%% Module attribute
#{ edits => [change(NewName, {0, 8}, {0, 23})]
, textDocument => #{uri => UriA}}
, textDocument => #{uri => UriA, version => null}}
%% Rename file
, #{ kind => <<"rename">>
, newUri => NewUri
, oldUri => UriA}
%% Implicit function
, #{ edits => [change(NewName, {12, 10}, {12, 25})]
, textDocument => #{uri => UriB}}
, textDocument => #{uri => UriB, version => null}}
%% Function application
, #{ edits => [change(NewName, {11, 2}, {11, 17})]
, textDocument => #{uri => UriB}}
, textDocument => #{uri => UriB, version => null}}
%% Import
, #{ edits => [change(NewName, {3, 8}, {3, 23})]
, textDocument => #{uri => UriB}}
, textDocument => #{uri => UriB, version => null}}
%% Type application
, #{ edits => [change(NewName, {7, 18}, {7, 33})]
, textDocument => #{uri => UriB}}
, textDocument => #{uri => UriB, version => null}}
%% Behaviour
, #{ edits => [change(NewName, {2, 11}, {2, 26})]
, textDocument => #{uri => UriB}}
, textDocument => #{uri => UriB, version => null}}
],
?assertEqual([], Result -- Expected),
?assertEqual([], Expected -- Result),
Expand Down

0 comments on commit a24f3e9

Please sign in to comment.