mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 20:13:32 +01:00
[css] support rename
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
'use strict';
|
||||
|
||||
import {TextDocument, Position, CompletionList, Hover, Range, SymbolInformation, Diagnostic,
|
||||
Location, DocumentHighlight, CodeActionContext, Command} from 'vscode-languageserver';
|
||||
Location, DocumentHighlight, CodeActionContext, Command, WorkspaceEdit} from 'vscode-languageserver';
|
||||
|
||||
import {Stylesheet} from './parser/cssNodes';
|
||||
import {Parser} from './parser/cssParser';
|
||||
@@ -32,6 +32,7 @@ export interface LanguageService {
|
||||
findDocumentSymbols(document: TextDocument, stylesheet: Stylesheet): Thenable<SymbolInformation[]>;
|
||||
doCodeActions(document: TextDocument, range: Range, context: CodeActionContext, stylesheet: Stylesheet): Thenable<Command[]>;
|
||||
findColorSymbols(document: TextDocument, stylesheet: Stylesheet): Thenable<Range[]>;
|
||||
doRename(document: TextDocument, position: Position, newName: string, stylesheet: Stylesheet): Thenable<WorkspaceEdit>;
|
||||
}
|
||||
|
||||
export interface LanguageSettings {
|
||||
@@ -58,7 +59,8 @@ export function getCSSLanguageService() : LanguageService {
|
||||
findDocumentHighlights: cssNavigation.findDocumentHighlights.bind(cssNavigation),
|
||||
findDocumentSymbols: cssNavigation.findDocumentSymbols.bind(cssNavigation),
|
||||
doCodeActions: cssCodeActions.doCodeActions.bind(cssCodeActions),
|
||||
findColorSymbols: cssNavigation.findColorSymbols.bind(cssNavigation)
|
||||
findColorSymbols: cssNavigation.findColorSymbols.bind(cssNavigation),
|
||||
doRename: cssNavigation.doRename.bind(cssNavigation),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,8 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
|
||||
referencesProvider: true,
|
||||
definitionProvider: true,
|
||||
documentHighlightProvider: true,
|
||||
codeActionProvider: true
|
||||
codeActionProvider: true,
|
||||
renameProvider: true
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -176,5 +177,11 @@ connection.onRequest(ColorSymbolRequest.type, uri => {
|
||||
return getLanguageService(document).findColorSymbols(document, stylesheet);
|
||||
});
|
||||
|
||||
connection.onRenameRequest(renameParameters => {
|
||||
let document = documents.get(renameParameters.textDocument.uri);
|
||||
let stylesheet = stylesheets.getStylesheet(document);
|
||||
return getLanguageService(document).doRename(document, renameParameters.position, renameParameters.newName, stylesheet);
|
||||
});
|
||||
|
||||
// Listen on the connection
|
||||
connection.listen();
|
||||
@@ -5,7 +5,8 @@
|
||||
'use strict';
|
||||
|
||||
import * as nodes from '../parser/cssNodes';
|
||||
import {TextDocument, Range, Position, Location, DocumentHighlightKind, DocumentHighlight, SymbolInformation, SymbolKind} from 'vscode-languageserver';
|
||||
import {TextDocument, Range, Position, Location, DocumentHighlightKind, DocumentHighlight,
|
||||
SymbolInformation, SymbolKind, WorkspaceEdit, TextEdit} from 'vscode-languageserver';
|
||||
import {Symbols} from '../parser/cssSymbolScope';
|
||||
import {isColorValue} from '../services/languageFacts';
|
||||
|
||||
@@ -137,6 +138,18 @@ export class CSSNavigation {
|
||||
});
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
||||
public doRename(document: TextDocument, position: Position, newName: string, stylesheet: nodes.Stylesheet): Thenable<WorkspaceEdit> {
|
||||
return this.findDocumentHighlights(document, position, stylesheet).then(highlights => {
|
||||
let edits = highlights.map(h => TextEdit.replace(h.range, newName));
|
||||
return {
|
||||
changes: {
|
||||
[document.uri]: edits
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getRange(node: nodes.Node, document: TextDocument) : Range {
|
||||
|
||||
Reference in New Issue
Block a user