beta version for folder rename
This commit is contained in:
parent
c08391ce32
commit
0d86e22229
@ -85,8 +85,9 @@ pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabiliti
|
|||||||
matches: Some(FileOperationPatternKind::File),
|
matches: Some(FileOperationPatternKind::File),
|
||||||
options: None,
|
options: None,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
FileOperationFilter {
|
FileOperationFilter {
|
||||||
scheme: Some(String::from("untitled")),
|
scheme: Some(String::from("file")),
|
||||||
pattern: FileOperationPattern {
|
pattern: FileOperationPattern {
|
||||||
glob: String::from("**"),
|
glob: String::from("**"),
|
||||||
matches: Some(FileOperationPatternKind::Folder),
|
matches: Some(FileOperationPatternKind::Folder),
|
||||||
|
@ -432,9 +432,26 @@ pub(crate) fn handle_will_rename_files(
|
|||||||
// Limit to single-level moves for now.
|
// Limit to single-level moves for now.
|
||||||
match (from_path.parent(), to_path.parent()) {
|
match (from_path.parent(), to_path.parent()) {
|
||||||
(Some(p1), Some(p2)) if p1 == p2 => {
|
(Some(p1), Some(p2)) if p1 == p2 => {
|
||||||
let new_name = to_path.file_stem()?;
|
if from_path.is_dir() {
|
||||||
let new_name = new_name.to_str()?;
|
// This is a quick implement, try to use will_rename_file code.
|
||||||
Some((snap.url_to_file_id(&from).ok()?, new_name.to_string()))
|
// imitate change the older_folder/mod.rs to older_folder/new_folder.rs
|
||||||
|
let imitate_from_path = from_path.join("mod.rs");
|
||||||
|
let new_from_url = imitate_from_path.to_str()?;
|
||||||
|
let new_from_url = Url::parse(new_from_url).ok()?;
|
||||||
|
|
||||||
|
let new_folder_name = to_path.file_name()?.to_str()?;
|
||||||
|
let mut imite_new_file_name = new_folder_name.to_string();
|
||||||
|
imite_new_file_name.push_str(".rs");
|
||||||
|
let new_to = from_path.join(imite_new_file_name);
|
||||||
|
let new_to = new_to.to_str()?;
|
||||||
|
|
||||||
|
Some((snap.url_to_file_id(&new_from_url).ok()?, new_to.to_string()))
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
let new_name = to_path.file_stem()?;
|
||||||
|
let new_name = new_name.to_str()?;
|
||||||
|
Some((snap.url_to_file_id(&from).ok()?, new_name.to_string()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
@ -51,12 +51,24 @@ export function createClient(serverPath: string, cwd: string, extraEnv: Env): lc
|
|||||||
'Rust Analyzer Language Server Trace',
|
'Rust Analyzer Language Server Trace',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const workspace:lc.WorkspaceMiddleware = {
|
||||||
|
willRenameFiles:function<P extends vscode.FileRenameEvent,R extends Thenable<vscode.WorkspaceEdit | null | undefined>>(this: void, data: P, next:(data: P) => R ){
|
||||||
|
// why add this function rather than default:
|
||||||
|
// 1. change `url` parameter to happy format for url crate. (folder should end with '/')
|
||||||
|
// 2. filter some change in here.
|
||||||
|
// 2.1 rename from or to `mod.rs` should be special.
|
||||||
|
// 2.2 not all folder change should be cared, only those have files with ".rs" postfix.
|
||||||
|
return next(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const clientOptions: lc.LanguageClientOptions = {
|
const clientOptions: lc.LanguageClientOptions = {
|
||||||
documentSelector: [{ scheme: 'file', language: 'rust' }],
|
documentSelector: [{ scheme: 'file', language: 'rust' }],
|
||||||
initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"),
|
initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"),
|
||||||
diagnosticCollectionName: "rustc",
|
diagnosticCollectionName: "rustc",
|
||||||
traceOutputChannel,
|
traceOutputChannel,
|
||||||
middleware: {
|
middleware: {
|
||||||
|
workspace,
|
||||||
provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken, next: DocumentSemanticsTokensSignature): vscode.ProviderResult<vscode.SemanticTokens> {
|
provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken, next: DocumentSemanticsTokensSignature): vscode.ProviderResult<vscode.SemanticTokens> {
|
||||||
return semanticHighlightingWorkaround(next, document, token);
|
return semanticHighlightingWorkaround(next, document, token);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user