-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
make path changes LSP spec conformant #8949
Conversation
@@ -1222,7 +1305,7 @@ impl Editor { | |||
.collect::<HashMap<_, _>>() | |||
}); | |||
|
|||
if language_servers.is_empty() { | |||
if language_servers.is_empty() && doc.language_servers.is_empty() { |
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.
existing bug that I noticed that I fixetd since its related (to refreshing document language)
helix-view/src/handlers/lsp.rs
Outdated
let edits = document_edit | ||
.edits | ||
.iter() | ||
.map(|edit| match edit { | ||
lsp::OneOf::Left(text_edit) => text_edit, | ||
lsp::OneOf::Right(annotated_text_edit) => { | ||
&annotated_text_edit.text_edit | ||
} | ||
}) | ||
.cloned() | ||
.collect(); | ||
apply_edits( | ||
self, | ||
&document_edit.text_document.uri, | ||
document_edit.text_document.version, | ||
edits, | ||
) | ||
.map_err(|kind| { | ||
ApplyEditError { | ||
kind, | ||
failed_change_idx: i, | ||
} | ||
})?; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return Ok(()); | ||
} | ||
|
||
if let Some(ref changes) = workspace_edit.changes { | ||
log::debug!("workspace changes: {:?}", changes); | ||
for (i, (uri, text_edits)) in changes.iter().enumerate() { | ||
let text_edits = text_edits.to_vec(); | ||
apply_edits(self, uri, None, text_edits).map_err(|kind| ApplyEditError { | ||
kind, | ||
failed_change_idx: i, | ||
})?; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn apply_document_resource_op(&mut self, op: &lsp::ResourceOp) -> std::io::Result<()> { | ||
use lsp::ResourceOp; | ||
use std::fs; | ||
match op { | ||
ResourceOp::Create(op) => { | ||
let path = op.uri.to_file_path().unwrap(); | ||
let ignore_if_exists = op.options.as_ref().map_or(false, |options| { | ||
!options.overwrite.unwrap_or(false) && options.ignore_if_exists.unwrap_or(false) | ||
}); | ||
if !ignore_if_exists || !path.exists() { | ||
// Create directory if it does not exist | ||
if let Some(dir) = path.parent() { | ||
if !dir.is_dir() { | ||
fs::create_dir_all(dir)?; | ||
} | ||
} | ||
|
||
fs::write(&path, [])?; | ||
self.language_servers.file_event_handler.file_changed(path); | ||
} | ||
} | ||
ResourceOp::Delete(op) => { | ||
let path = op.uri.to_file_path().unwrap(); | ||
if path.is_dir() { | ||
let recursive = op | ||
.options | ||
.as_ref() | ||
.and_then(|options| options.recursive) | ||
.unwrap_or(false); | ||
|
||
if recursive { | ||
fs::remove_dir_all(&path)? | ||
} else { | ||
fs::remove_dir(&path)? | ||
} | ||
self.language_servers.file_event_handler.file_changed(path); | ||
} else if path.is_file() { | ||
fs::remove_file(&path)?; | ||
} | ||
} | ||
ResourceOp::Rename(op) => { | ||
let from = op.old_uri.to_file_path().unwrap(); | ||
let to = op.new_uri.to_file_path().unwrap(); | ||
let ignore_if_exists = op.options.as_ref().map_or(false, |options| { | ||
!options.overwrite.unwrap_or(false) && options.ignore_if_exists.unwrap_or(false) | ||
}); | ||
if !ignore_if_exists || !to.exists() { | ||
self.move_path(&from, &to)?; | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} |
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.
this was moved here from helix_term and responsible for most of the diff. I needed to call this from editor.rs. I think this never belonged in helix-term to begin with.
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.
Does this also fix #5300?
hmm I am not entirely sure. The answer is mostly no. I don't touch the I could create a similar I am not sure if that issue was always jus a refactoring issue or if this has been fixed elsewhere (potentially the multilsp PR) |
7491577
to
f74d6a5
Compare
56e725f
to
ee1a4ad
Compare
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've been testing this for a while with no problems and the changes look good to me. It's nice to have the Editor::apply_workspace_edits
and Editor::move_path
functionality centralized on the Editor now 👍
(not to mention starting to use the helix-view/src/handlers/lsp.rs
file now :P)
ee1a4ad
to
4635b5f
Compare
rebased as there were quite a few conflicts |
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.
LGTM just needs one last rebase
c8e41f6
4635b5f
to
c8e41f6
Compare
Currently, helix implements operations which change the paths of files incorrectly and inconsistently. This PR ensures that we do the following whenever a buffer is renamed (`:move` and workspace edits) * always send did_open/did_close notifications * send will_rename/did_rename requests correctly * send them to all LSP servers not just those that are active for a buffer * also send these requests for paths that are not yet open in a buffer (if triggered from workspace edit). * only send these if the server registered interests in the path * autodetect language, indent, line ending, .. This PR also centralizes the infrastructure for path setting and therefore `:w <path>` benefits from similar fixed (but without didRename)
c8e41f6
to
8c23d3a
Compare
rebased again to resolve conflicts with #8021 (no real changes just conflicts in use statements) |
Currently, helix implements operations which change the paths of files incorrectly and inconsistently. This PR ensures that we do the following whenever a buffer is renamed (`:move` and workspace edits) * always send did_open/did_close notifications * send will_rename/did_rename requests correctly * send them to all LSP servers not just those that are active for a buffer * also send these requests for paths that are not yet open in a buffer (if triggered from workspace edit). * only send these if the server registered interests in the path * autodetect language, indent, line ending, .. This PR also centralizes the infrastructure for path setting and therefore `:w <path>` benefits from similar fixed (but without didRename)
Currently, helix implements operations which change the paths of files incorrectly and inconsistently. This PR ensures that we do the following whenever a buffer is renamed (`:move` and workspace edits) * always send did_open/did_close notifications * send will_rename/did_rename requests correctly * send them to all LSP servers not just those that are active for a buffer * also send these requests for paths that are not yet open in a buffer (if triggered from workspace edit). * only send these if the server registered interests in the path * autodetect language, indent, line ending, .. This PR also centralizes the infrastructure for path setting and therefore `:w <path>` benefits from similar fixed (but without didRename)
Currently, helix implements operations which change the paths of files incorrectly and inconsistently. This PR ensures that we do the following whenever a buffer is renamed (`:move` and workspace edits) * always send did_open/did_close notifications * send will_rename/did_rename requests correctly * send them to all LSP servers not just those that are active for a buffer * also send these requests for paths that are not yet open in a buffer (if triggered from workspace edit). * only send these if the server registered interests in the path * autodetect language, indent, line ending, .. This PR also centralizes the infrastructure for path setting and therefore `:w <path>` benefits from similar fixed (but without didRename)
Currently, helix implements operations which change the paths of files incorrectly and inconsistently. This PR ensures that we do the following whenever a buffer is renamed (`:move` and workspace edits) * always send did_open/did_close notifications * send will_rename/did_rename requests correctly * send them to all LSP servers not just those that are active for a buffer * also send these requests for paths that are not yet open in a buffer (if triggered from workspace edit). * only send these if the server registered interests in the path * autodetect language, indent, line ending, .. This PR also centralizes the infrastructure for path setting and therefore `:w <path>` benefits from similar fixed (but without didRename)
Currently, helix implements operations which change the paths of files incorrectly and inconsistently. This PR ensures that we do the following whenever a buffer is renamed (`:move` and workspace edits) * always send did_open/did_close notifications * send will_rename/did_rename requests correctly * send them to all LSP servers not just those that are active for a buffer * also send these requests for paths that are not yet open in a buffer (if triggered from workspace edit). * only send these if the server registered interests in the path * autodetect language, indent, line ending, .. This PR also centralizes the infrastructure for path setting and therefore `:w <path>` benefits from similar fixed (but without didRename)
Closes #8942
Supercedes #8924
Currently, helix implements operations which change the paths of files
incorrectly and inconsistently. This PR ensures that we do the following
whenever a buffer is renamed (
:move
and workspace edits)buffer
triggered from workspace edit).
This PR also centralizes the infrastructure for path setting and
therefore
:w <path>
benefits from similar fixed (but withoutdidRename
andwillRename
).I also used the chance to move the
apply_workspace_edit
function tohelix_view
(as that was required anyway to avoid pushing a bunch of new logic down tohelix_term
that really didn't belong there).