/// Gets the language server that is attached to a document, and
/// Gets the language server that is attached to a document, and
/// if it's not active displays a status message. Using this macro
/// if it's not active displays a status message. Using this macro
@ -211,7 +211,6 @@ fn sym_picker(
Ok(path)=>path,
Ok(path)=>path,
Err(_)=>{
Err(_)=>{
leterr=format!("unable to convert URI to filepath: {}",uri);
leterr=format!("unable to convert URI to filepath: {}",uri);
log::error!("{}",err);
cx.editor.set_error(err);
cx.editor.set_error(err);
return;
return;
}
}
@ -421,6 +420,63 @@ impl ui::menu::Item for lsp::CodeActionOrCommand {
}
}
}
}
/// Determines the category of the `CodeAction` using the `CodeAction::kind` field.
/// Returns a number that represent these categories.
/// Categories with a lower number should be displayed first.
///
///
/// While the `kind` field is defined as open ended in the LSP spec (any value may be used)
/// in practice a closed set of common values (mostly suggested in the LSP spec) are used.
/// VSCode displays each of these categories seperatly (seperated by a heading in the codeactions picker)
/// to make them easier to navigate. Helix does not display these headings to the user.
/// However it does sort code actions by their categories to achieve the same order as the VScode picker,
/// just without the headings.
///
/// The order used here is modeled after the [vscode sourcecode](https://github.com/microsoft/vscode/blob/eaec601dd69aeb4abb63b9601a6f44308c8d8c6e/src/vs/editor/contrib/codeAction/browser/codeActionWidget.ts>)
// Sort codeactions into a useful order. This behaviour is only partially described in the LSP spec.
// this ensures that the most relevant codeactions (quickfix) show up first
// Many details are modeled after vscode because langauge servers are usually tested against it.
// while more situational commands (like refactors) show up later
// VScode sorts the codeaction two times:
// this behaviour is modeled after the behaviour of vscode (https://github.com/microsoft/vscode/blob/eaec601dd69aeb4abb63b9601a6f44308c8d8c6e/src/vs/editor/contrib/codeAction/browser/codeActionWidget.ts)
//
// First the codeactions that fix some diagnostics are moved to the front.
actions.sort_by_key(|action|match&action{
// If both codeactions fix some diagnostics (or both fix none) the codeaction