typescript-language-server
Advanced tools
Comparing version 0.0.15 to 0.0.16
@@ -27,2 +27,3 @@ "use strict"; | ||
this.connection.onReferences(this.onReferences.bind(this)); | ||
this.connection.onRenameRequest(this.onRename.bind(this)); | ||
this.connection.onWorkspaceSymbol(this.onWorkspaceSymbol.bind(this)); | ||
@@ -54,2 +55,3 @@ } | ||
hoverProvider: true, | ||
renameProvider: true, | ||
referencesProvider: true, | ||
@@ -160,2 +162,29 @@ workspaceSymbolProvider: true | ||
} | ||
onRename(params) { | ||
const path = utils.uriToPath(params.textDocument.uri); | ||
this.logger.info('Server.onRename()', params, path); | ||
return this.tsServerClient.sendRename(path, params.position.line + 1, params.position.character + 1) | ||
.then(result => { | ||
if (!result.body || !result.body.info.canRename || result.body.locs.length == 0) { | ||
return {}; | ||
} | ||
const workspaceEdit = { | ||
changes: {} | ||
}; | ||
result.body.locs | ||
.forEach((spanGroup) => { | ||
const uri = utils.pathToUri(spanGroup.file), textEdits = workspaceEdit.changes[uri] || (workspaceEdit.changes[uri] = []); | ||
spanGroup.locs.forEach((textSpan) => { | ||
textEdits.push({ | ||
newText: params.newName, | ||
range: { | ||
start: utils.tsServerLocationToLspPosition(textSpan.start), | ||
end: utils.tsServerLocationToLspPosition(textSpan.end) | ||
} | ||
}); | ||
}); | ||
}); | ||
return workspaceEdit; | ||
}); | ||
} | ||
onReferences(params) { | ||
@@ -162,0 +191,0 @@ const path = utils.uriToPath(params.textDocument.uri); |
@@ -154,2 +154,7 @@ "use strict"; | ||
} | ||
sendRename(file, line, offset) { | ||
const args = { file, line, offset }; | ||
this.logger.info('TsServerClient.sendRename()', args); | ||
return this.sendRequest('rename', false, args); | ||
} | ||
sendReferences(file, line, offset) { | ||
@@ -156,0 +161,0 @@ const args = { file, line, offset }; |
{ | ||
"name": "typescript-language-server", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "Language Server Protocol (LSP) implementation for TypeScript using tsserver", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -49,2 +49,3 @@ # typescript-language-server | ||
* textDocument/hover | ||
* textDocument/rename | ||
* textDocument/references | ||
@@ -51,0 +52,0 @@ * workspace/symbol |
24565
504
68