typescript-language-server
Advanced tools
Comparing version 0.3.5 to 0.3.6
@@ -6,7 +6,9 @@ /// <reference types="p-debounce" /> | ||
import { EventTypes } from './tsp-command-types'; | ||
import { LspDocuments } from './document'; | ||
declare class FileDiagnostics { | ||
protected readonly uri: string; | ||
protected readonly publishDiagnostics: (params: lsp.PublishDiagnosticsParams) => void; | ||
protected readonly documents: LspDocuments; | ||
private readonly diagnosticsPerKind; | ||
constructor(uri: string, publishDiagnostics: (params: lsp.PublishDiagnosticsParams) => void); | ||
constructor(uri: string, publishDiagnostics: (params: lsp.PublishDiagnosticsParams) => void, documents: LspDocuments); | ||
update(kind: EventTypes, diagnostics: tsp.Diagnostic[]): void; | ||
@@ -19,6 +21,7 @@ protected readonly firePublishDiagnostics: (() => Promise<void>) & { | ||
export declare class DiagnosticEventQueue { | ||
protected publishDiagnostics: (params: lsp.PublishDiagnosticsParams) => void; | ||
protected logger: Logger; | ||
protected readonly publishDiagnostics: (params: lsp.PublishDiagnosticsParams) => void; | ||
protected readonly documents: LspDocuments; | ||
protected readonly logger: Logger; | ||
protected readonly diagnostics: Map<string, FileDiagnostics>; | ||
constructor(publishDiagnostics: (params: lsp.PublishDiagnosticsParams) => void, logger: Logger); | ||
constructor(publishDiagnostics: (params: lsp.PublishDiagnosticsParams) => void, documents: LspDocuments, logger: Logger); | ||
updateDiagnostics(kind: EventTypes, event: tsp.DiagnosticEvent): void; | ||
@@ -25,0 +28,0 @@ } |
@@ -12,5 +12,6 @@ "use strict"; | ||
class FileDiagnostics { | ||
constructor(uri, publishDiagnostics) { | ||
constructor(uri, publishDiagnostics, documents) { | ||
this.uri = uri; | ||
this.publishDiagnostics = publishDiagnostics; | ||
this.documents = documents; | ||
this.diagnosticsPerKind = new Map(); | ||
@@ -23,3 +24,3 @@ this.firePublishDiagnostics = debounce(() => { | ||
update(kind, diagnostics) { | ||
this.diagnosticsPerKind.set(kind, diagnostics.map(protocol_translation_1.toDiagnostic)); | ||
this.diagnosticsPerKind.set(kind, diagnostics); | ||
this.firePublishDiagnostics(); | ||
@@ -29,4 +30,6 @@ } | ||
const result = []; | ||
for (const value of this.diagnosticsPerKind.values()) { | ||
result.push(...value); | ||
for (const diagnostics of this.diagnosticsPerKind.values()) { | ||
for (const diagnostic of diagnostics) { | ||
result.push(protocol_translation_1.toDiagnostic(diagnostic, this.documents)); | ||
} | ||
} | ||
@@ -37,4 +40,5 @@ return result; | ||
class DiagnosticEventQueue { | ||
constructor(publishDiagnostics, logger) { | ||
constructor(publishDiagnostics, documents, logger) { | ||
this.publishDiagnostics = publishDiagnostics; | ||
this.documents = documents; | ||
this.logger = logger; | ||
@@ -49,5 +53,6 @@ this.diagnostics = new Map(); | ||
const { file } = event.body; | ||
const diagnostics = this.diagnostics.get(file) || new FileDiagnostics(protocol_translation_1.pathToUri(file), this.publishDiagnostics); | ||
const uri = protocol_translation_1.pathToUri(file, this.documents); | ||
const diagnostics = this.diagnostics.get(uri) || new FileDiagnostics(uri, this.publishDiagnostics, this.documents); | ||
diagnostics.update(kind, event.body.diagnostics); | ||
this.diagnostics.set(file, diagnostics); | ||
this.diagnostics.set(uri, diagnostics); | ||
} | ||
@@ -54,0 +59,0 @@ } |
@@ -43,3 +43,3 @@ "use strict"; | ||
this.logger = new logger_1.PrefixingLogger(options.logger, '[lspserver]'); | ||
this.diagnosticQueue = new diagnostic_queue_1.DiagnosticEventQueue(diagnostics => this.options.lspClient.publishDiagnostics(diagnostics), this.logger); | ||
this.diagnosticQueue = new diagnostic_queue_1.DiagnosticEventQueue(diagnostics => this.options.lspClient.publishDiagnostics(diagnostics), this.documents, this.logger); | ||
} | ||
@@ -99,3 +99,3 @@ closeAll() { | ||
}); | ||
const logFileUri = logFile && protocol_translation_1.pathToUri(logFile); | ||
const logFileUri = logFile && protocol_translation_1.pathToUri(logFile, undefined); | ||
this.initializeResult = { | ||
@@ -335,3 +335,3 @@ capabilities: { | ||
}); | ||
return result.body ? result.body.map(fileSpan => protocol_translation_1.toLocation(fileSpan)) : []; | ||
return result.body ? result.body.map(fileSpan => protocol_translation_1.toLocation(fileSpan, this.documents)) : []; | ||
}); | ||
@@ -466,3 +466,3 @@ } | ||
.forEach((spanGroup) => { | ||
const uri = protocol_translation_1.pathToUri(spanGroup.file), textEdits = workspaceEdit.changes[uri] || (workspaceEdit.changes[uri] = []); | ||
const uri = protocol_translation_1.pathToUri(spanGroup.file, this.documents), textEdits = workspaceEdit.changes[uri] || (workspaceEdit.changes[uri] = []); | ||
spanGroup.locs.forEach((textSpan) => { | ||
@@ -497,3 +497,3 @@ textEdits.push({ | ||
return result.body.refs | ||
.map(fileSpan => protocol_translation_1.toLocation(fileSpan)); | ||
.map(fileSpan => protocol_translation_1.toLocation(fileSpan, this.documents)); | ||
}); | ||
@@ -579,3 +579,3 @@ } | ||
const errorCodes = params.context.diagnostics.map(diagnostic => Number(diagnostic.code)); | ||
quickfix_1.provideQuickFix(yield this.getCodeFixes(Object.assign({}, args, { errorCodes })), codeActions); | ||
quickfix_1.provideQuickFix(yield this.getCodeFixes(Object.assign({}, args, { errorCodes })), codeActions, this.documents); | ||
refactor_1.provideRefactors(yield this.getRefactors(args), codeActions, args); | ||
@@ -642,3 +642,3 @@ organize_imports_1.provideOrganizeImports(file, params.context, codeActions); | ||
textDocument: { | ||
uri: protocol_translation_1.pathToUri(args.file) | ||
uri: protocol_translation_1.pathToUri(args.file, this.documents) | ||
}, | ||
@@ -675,3 +675,3 @@ position: protocol_translation_1.toPosition(renameLocation) | ||
for (const edit of edits) { | ||
changes[protocol_translation_1.pathToUri(edit.fileName)] = edit.textChanges.map(protocol_translation_1.toTextEdit); | ||
changes[protocol_translation_1.pathToUri(edit.fileName, this.documents)] = edit.textChanges.map(protocol_translation_1.toTextEdit); | ||
} | ||
@@ -759,3 +759,3 @@ const { applied } = yield this.options.lspClient.applyWorkspaceEdit({ | ||
location: { | ||
uri: protocol_translation_1.pathToUri(item.file), | ||
uri: protocol_translation_1.pathToUri(item.file, this.documents), | ||
range: { | ||
@@ -762,0 +762,0 @@ start: protocol_translation_1.toPosition(item.start), |
import * as lsp from 'vscode-languageserver'; | ||
import * as tsp from 'typescript/lib/protocol'; | ||
import { LspDocuments } from './document'; | ||
export declare function uriToPath(stringUri: string): string | undefined; | ||
export declare function pathToUri(p: string): string; | ||
export declare function pathToUri(filepath: string, documents: LspDocuments | undefined): string; | ||
export declare function toPosition(location: tsp.Location): lsp.Position; | ||
export declare function toLocation(fileSpan: tsp.FileSpan): lsp.Location; | ||
export declare function toLocation(fileSpan: tsp.FileSpan, documents: LspDocuments | undefined): lsp.Location; | ||
export declare function toFileRangeRequestArgs(file: string, range: lsp.Range): tsp.FileRangeRequestArgs; | ||
export declare function toSymbolKind(tspKind: string): lsp.SymbolKind; | ||
export declare function toDiagnosticSeverity(category: string): lsp.DiagnosticSeverity; | ||
export declare function toDiagnostic(diagnostic: tsp.Diagnostic): lsp.Diagnostic; | ||
export declare function asRelatedInformation(info: tsp.DiagnosticRelatedInformation[] | undefined): lsp.DiagnosticRelatedInformation[] | undefined; | ||
export declare function toDiagnostic(diagnostic: tsp.Diagnostic, documents: LspDocuments | undefined): lsp.Diagnostic; | ||
export declare function asRelatedInformation(info: tsp.DiagnosticRelatedInformation[] | undefined, documents: LspDocuments | undefined): lsp.DiagnosticRelatedInformation[] | undefined; | ||
export declare function toTextEdit(edit: tsp.CodeEdit): lsp.TextEdit; | ||
export declare function toMarkDown(documentation: tsp.SymbolDisplayPart[], tags: tsp.JSDocTagInfo[]): string; | ||
export declare function toTextDocumentEdit(change: tsp.FileCodeEdits): lsp.TextDocumentEdit; | ||
export declare function toTextDocumentEdit(change: tsp.FileCodeEdits, documents: LspDocuments | undefined): lsp.TextDocumentEdit; | ||
export declare function toDocumentHighlight(item: tsp.DocumentHighlightsItem): lsp.DocumentHighlight[]; | ||
@@ -16,0 +17,0 @@ export declare function asRange(span: tsp.TextSpan): lsp.Range; |
@@ -11,3 +11,2 @@ "use strict"; | ||
const vscode_uri_1 = require("vscode-uri"); | ||
const utils_1 = require("./utils"); | ||
function uriToPath(stringUri) { | ||
@@ -21,4 +20,6 @@ const uri = vscode_uri_1.default.parse(stringUri); | ||
exports.uriToPath = uriToPath; | ||
function pathToUri(p) { | ||
return 'file://' + (utils_1.isWindows() ? '/' + p.replace(/\//g, '/') : p); | ||
function pathToUri(filepath, documents) { | ||
const fileUri = vscode_uri_1.default.file(filepath); | ||
const document = documents && documents.get(fileUri.fsPath); | ||
return document ? document.uri : fileUri.toString(); | ||
} | ||
@@ -33,5 +34,5 @@ exports.pathToUri = pathToUri; | ||
exports.toPosition = toPosition; | ||
function toLocation(fileSpan) { | ||
function toLocation(fileSpan, documents) { | ||
return { | ||
uri: pathToUri(fileSpan.file), | ||
uri: pathToUri(fileSpan.file, documents), | ||
range: { | ||
@@ -93,3 +94,3 @@ start: toPosition(fileSpan.start), | ||
exports.toDiagnosticSeverity = toDiagnosticSeverity; | ||
function toDiagnostic(diagnostic) { | ||
function toDiagnostic(diagnostic, documents) { | ||
return { | ||
@@ -104,7 +105,7 @@ range: { | ||
source: diagnostic.source || 'typescript', | ||
relatedInformation: asRelatedInformation(diagnostic.relatedInformation) | ||
relatedInformation: asRelatedInformation(diagnostic.relatedInformation, documents) | ||
}; | ||
} | ||
exports.toDiagnostic = toDiagnostic; | ||
function asRelatedInformation(info) { | ||
function asRelatedInformation(info, documents) { | ||
if (!info) { | ||
@@ -117,3 +118,3 @@ return undefined; | ||
if (span) { | ||
result.push(lsp.DiagnosticRelatedInformation.create(toLocation(span), item.message)); | ||
result.push(lsp.DiagnosticRelatedInformation.create(toLocation(span, documents), item.message)); | ||
} | ||
@@ -155,6 +156,6 @@ } | ||
exports.toMarkDown = toMarkDown; | ||
function toTextDocumentEdit(change) { | ||
function toTextDocumentEdit(change, documents) { | ||
return { | ||
textDocument: { | ||
uri: pathToUri(change.fileName), | ||
uri: pathToUri(change.fileName, documents), | ||
version: 0 // TODO | ||
@@ -161,0 +162,0 @@ }, |
import * as lsp from 'vscode-languageserver'; | ||
import * as tsp from 'typescript/lib/protocol'; | ||
export declare function provideQuickFix(response: tsp.GetCodeFixesResponse | undefined, result: (lsp.Command | lsp.CodeAction)[]): void; | ||
import { LspDocuments } from './document'; | ||
export declare function provideQuickFix(response: tsp.GetCodeFixesResponse | undefined, result: (lsp.Command | lsp.CodeAction)[], documents: LspDocuments | undefined): void; | ||
//# sourceMappingURL=quickfix.d.ts.map |
@@ -11,3 +11,3 @@ "use strict"; | ||
const protocol_translation_1 = require("./protocol-translation"); | ||
function provideQuickFix(response, result) { | ||
function provideQuickFix(response, result, documents) { | ||
if (!response || !response.body) { | ||
@@ -21,3 +21,3 @@ return; | ||
arguments: [{ | ||
documentChanges: fix.changes.map(c => protocol_translation_1.toTextDocumentEdit(c)) | ||
documentChanges: fix.changes.map(c => protocol_translation_1.toTextDocumentEdit(c, documents)) | ||
}] | ||
@@ -24,0 +24,0 @@ }); |
@@ -25,3 +25,3 @@ "use strict"; | ||
const resolved = this.filePath(suffix); | ||
return protocol_translation_1.pathToUri(resolved); | ||
return protocol_translation_1.pathToUri(resolved, undefined); | ||
} | ||
@@ -28,0 +28,0 @@ exports.uri = uri; |
{ | ||
"name": "typescript-language-server", | ||
"version": "0.3.5", | ||
"version": "0.3.6", | ||
"description": "Language Server Protocol (LSP) implementation for TypeScript using tsserver", | ||
@@ -37,3 +37,3 @@ "author": "TypeFox and others", | ||
}, | ||
"gitHead": "bd9b6c738c256a618d14cf5cd240993c2cedec24" | ||
"gitHead": "dbcdb541f191e98c6c55a7374039d184f433d4bb" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
258664
3358