typescript-language-server
Advanced tools
Comparing version 0.4.0-dev.a1b151f to 0.4.0-dev.b361793
@@ -6,13 +6,24 @@ /// <reference types="p-debounce" /> | ||
import { EventTypes } from './tsp-command-types'; | ||
export declare class DiagnosticEventQueue { | ||
protected publicDiagnostics: (params: lsp.PublishDiagnosticsParams) => void; | ||
protected logger: Logger; | ||
protected readonly diagnostics: Map<string, Map<EventTypes, lsp.Diagnostic[]>>; | ||
constructor(publicDiagnostics: (params: lsp.PublishDiagnosticsParams) => void, logger: Logger); | ||
updateDiagnostics(kind: EventTypes, event: tsp.DiagnosticEvent): void; | ||
protected firePublishDiagnostics: ((arg1: string) => Promise<void>) & { | ||
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, documents: LspDocuments); | ||
update(kind: EventTypes, diagnostics: tsp.Diagnostic[]): void; | ||
protected readonly firePublishDiagnostics: (() => Promise<void>) & { | ||
abort(): void; | ||
}; | ||
protected getDiagnostics(file: string): lsp.Diagnostic[]; | ||
protected getDiagnostics(): lsp.Diagnostic[]; | ||
} | ||
export declare class DiagnosticEventQueue { | ||
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, documents: LspDocuments, logger: Logger); | ||
updateDiagnostics(kind: EventTypes, event: tsp.DiagnosticEvent): void; | ||
} | ||
export {}; | ||
//# sourceMappingURL=diagnostic-queue.d.ts.map |
@@ -11,12 +11,33 @@ "use strict"; | ||
const debounce = require("p-debounce"); | ||
class FileDiagnostics { | ||
constructor(uri, publishDiagnostics, documents) { | ||
this.uri = uri; | ||
this.publishDiagnostics = publishDiagnostics; | ||
this.documents = documents; | ||
this.diagnosticsPerKind = new Map(); | ||
this.firePublishDiagnostics = debounce(() => { | ||
const diagnostics = this.getDiagnostics(); | ||
this.publishDiagnostics({ uri: this.uri, diagnostics }); | ||
}, 50); | ||
} | ||
update(kind, diagnostics) { | ||
this.diagnosticsPerKind.set(kind, diagnostics); | ||
this.firePublishDiagnostics(); | ||
} | ||
getDiagnostics() { | ||
const result = []; | ||
for (const diagnostics of this.diagnosticsPerKind.values()) { | ||
for (const diagnostic of diagnostics) { | ||
result.push(protocol_translation_1.toDiagnostic(diagnostic, this.documents)); | ||
} | ||
} | ||
return result; | ||
} | ||
} | ||
class DiagnosticEventQueue { | ||
constructor(publicDiagnostics, logger) { | ||
this.publicDiagnostics = publicDiagnostics; | ||
constructor(publishDiagnostics, documents, logger) { | ||
this.publishDiagnostics = publishDiagnostics; | ||
this.documents = documents; | ||
this.logger = logger; | ||
this.diagnostics = new Map(); | ||
this.firePublishDiagnostics = debounce((file) => { | ||
const uri = protocol_translation_1.pathToUri(file); | ||
const diagnostics = this.getDiagnostics(file); | ||
this.publicDiagnostics({ uri, diagnostics }); | ||
}, 50); | ||
} | ||
@@ -29,20 +50,9 @@ updateDiagnostics(kind, event) { | ||
const { file } = event.body; | ||
const diagnostics = this.diagnostics.get(file) || new Map(); | ||
diagnostics.set(kind, event.body.diagnostics.map(protocol_translation_1.toDiagnostic)); | ||
this.diagnostics.set(file, diagnostics); | ||
this.firePublishDiagnostics(file); | ||
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(uri, diagnostics); | ||
} | ||
getDiagnostics(file) { | ||
const diagnostics = this.diagnostics.get(file); | ||
if (!diagnostics) { | ||
return []; | ||
} | ||
const result = []; | ||
for (const value of diagnostics.values()) { | ||
result.push(...value); | ||
} | ||
return result; | ||
} | ||
} | ||
exports.DiagnosticEventQueue = DiagnosticEventQueue; | ||
//# sourceMappingURL=diagnostic-queue.js.map |
@@ -5,3 +5,3 @@ import * as lsp from 'vscode-languageserver'; | ||
export declare function collectSymbolInformations(uri: string, current: tsp.NavigationTree, symbols: lsp.SymbolInformation[], containerName?: string): boolean; | ||
export declare function shouldInclueEntry(item: tsp.NavigationTree | tsp.NavigationBarItem): boolean; | ||
export declare function shouldIncludeEntry(item: tsp.NavigationTree | tsp.NavigationBarItem): boolean; | ||
//# sourceMappingURL=document-symbol.d.ts.map |
@@ -12,10 +12,17 @@ "use strict"; | ||
function collectDocumentSymbols(parent, symbols) { | ||
let shouldInclude = shouldInclueEntry(parent); | ||
return collectDocumentSymbolsInRange(parent, symbols, { start: protocol_translation_1.asRange(parent.spans[0]).start, end: protocol_translation_1.asRange(parent.spans[parent.spans.length - 1]).end }); | ||
} | ||
exports.collectDocumentSymbols = collectDocumentSymbols; | ||
function collectDocumentSymbolsInRange(parent, symbols, range) { | ||
let shouldInclude = shouldIncludeEntry(parent); | ||
for (const span of parent.spans) { | ||
const range = protocol_translation_1.asRange(span); | ||
const spanRange = protocol_translation_1.asRange(span); | ||
if (!protocol_translation_1.Range.intersection(range, spanRange)) { | ||
continue; | ||
} | ||
const children = []; | ||
if (parent.childItems) { | ||
for (const child of parent.childItems) { | ||
if (child.spans.some(span => !!protocol_translation_1.Range.intersection(range, protocol_translation_1.asRange(span)))) { | ||
const includedChild = collectDocumentSymbols(child, children); | ||
if (child.spans.some(childSpan => !!protocol_translation_1.Range.intersection(spanRange, protocol_translation_1.asRange(childSpan)))) { | ||
const includedChild = collectDocumentSymbolsInRange(child, children, spanRange); | ||
shouldInclude = shouldInclude || includedChild; | ||
@@ -25,2 +32,10 @@ } | ||
} | ||
let selectionRange = spanRange; | ||
if (parent.nameSpan) { | ||
const nameRange = protocol_translation_1.asRange(parent.nameSpan); | ||
// In the case of mergeable definitions, the nameSpan is only correct for the first definition. | ||
if (protocol_translation_1.Range.intersection(spanRange, nameRange)) { | ||
selectionRange = nameRange; | ||
} | ||
} | ||
if (shouldInclude) { | ||
@@ -31,4 +46,4 @@ symbols.push({ | ||
kind: protocol_translation_1.toSymbolKind(parent.kind), | ||
range, | ||
selectionRange: range, | ||
range: spanRange, | ||
selectionRange: selectionRange, | ||
children | ||
@@ -40,5 +55,4 @@ }); | ||
} | ||
exports.collectDocumentSymbols = collectDocumentSymbols; | ||
function collectSymbolInformations(uri, current, symbols, containerName) { | ||
let shouldInclude = shouldInclueEntry(current); | ||
let shouldInclude = shouldIncludeEntry(current); | ||
const name = current.text; | ||
@@ -72,3 +86,3 @@ for (const span of current.spans) { | ||
exports.collectSymbolInformations = collectSymbolInformations; | ||
function shouldInclueEntry(item) { | ||
function shouldIncludeEntry(item) { | ||
if (item.kind === tsp_command_types_1.ScriptElementKind.alias) { | ||
@@ -79,3 +93,3 @@ return false; | ||
} | ||
exports.shouldInclueEntry = shouldInclueEntry; | ||
exports.shouldIncludeEntry = shouldIncludeEntry; | ||
//# sourceMappingURL=document-symbol.js.map |
@@ -28,2 +28,4 @@ /// <reference types="p-debounce" /> | ||
initialize(params: TypeScriptInitializeParams): Promise<TypeScriptInitializeResult>; | ||
protected getLogFile(logVerbosity: string | undefined): string | undefined; | ||
protected doGetLogFile(): string | undefined; | ||
protected diagnosticsTokenSource: lsp.CancellationTokenSource | undefined; | ||
@@ -30,0 +32,0 @@ protected interuptDiagnostics<R>(f: () => R): R; |
@@ -17,2 +17,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path = require("path"); | ||
const tempy = require("tempy"); | ||
@@ -43,3 +44,3 @@ const lsp = require("vscode-languageserver"); | ||
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); | ||
} | ||
@@ -75,4 +76,10 @@ closeAll() { | ||
this.initializeParams = params; | ||
const { logVerbosity } = Object.assign({ logVerbosity: this.options.tsserverLogVerbosity }, this.initializeParams.initializationOptions); | ||
const logFile = logVerbosity !== undefined ? this.options.tsserverLogFile || tempy.file({ name: 'tsserver.log' }) : undefined; | ||
const { logVerbosity, plugins } = Object.assign({ logVerbosity: this.options.tsserverLogVerbosity, plugins: [] }, this.initializeParams.initializationOptions); | ||
const logFile = this.getLogFile(logVerbosity); | ||
const globalPlugins = []; | ||
const pluginProbeLocations = []; | ||
for (const plugin of plugins) { | ||
globalPlugins.push(plugin.name); | ||
pluginProbeLocations.push(plugin.location); | ||
} | ||
const tsserverPath = this.findTsserverPath(); | ||
@@ -83,2 +90,4 @@ this.tspClient = new tsp_client_1.TspClient({ | ||
logVerbosity, | ||
globalPlugins, | ||
pluginProbeLocations, | ||
logger: this.options.logger, | ||
@@ -93,3 +102,3 @@ onEvent: this.onTsEvent.bind(this) | ||
}); | ||
const logFileUri = logFile && protocol_translation_1.pathToUri(logFile); | ||
const logFileUri = logFile && protocol_translation_1.pathToUri(logFile, undefined); | ||
this.initializeResult = { | ||
@@ -133,2 +142,28 @@ capabilities: { | ||
} | ||
getLogFile(logVerbosity) { | ||
if (logVerbosity === undefined) { | ||
return undefined; | ||
} | ||
const logFile = this.doGetLogFile(); | ||
if (logFile) { | ||
fs.ensureFileSync(logFile); | ||
return logFile; | ||
} | ||
return tempy.file({ name: 'tsserver.log' }); | ||
} | ||
doGetLogFile() { | ||
if (process.env.TSSERVER_LOG_FILE) { | ||
return process.env.TSSERVER_LOG_FILE; | ||
} | ||
if (this.options.tsserverLogFile) { | ||
return this.options.tsserverLogFile; | ||
} | ||
if (this.initializeParams.rootUri) { | ||
return path.join(protocol_translation_1.uriToPath(this.initializeParams.rootUri), '.log/tsserver.log'); | ||
} | ||
if (this.initializeParams.rootPath) { | ||
return path.join(this.initializeParams.rootPath, '.log/tsserver.log'); | ||
} | ||
return undefined; | ||
} | ||
interuptDiagnostics(f) { | ||
@@ -235,3 +270,3 @@ if (!this.diagnosticsTokenSource) { | ||
if (textDocument.version === null) { | ||
throw new Error(`Recevied document change event for ${textDocument.uri} without valid version identifier`); | ||
throw new Error(`Received document change event for ${textDocument.uri} without valid version identifier`); | ||
} | ||
@@ -305,3 +340,3 @@ for (const change of params.contentChanges) { | ||
}); | ||
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)) : []; | ||
}); | ||
@@ -436,3 +471,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) => { | ||
@@ -467,3 +502,3 @@ textEdits.push({ | ||
return result.body.refs | ||
.map(fileSpan => protocol_translation_1.toLocation(fileSpan)); | ||
.map(fileSpan => protocol_translation_1.toLocation(fileSpan, this.documents)); | ||
}); | ||
@@ -549,3 +584,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); | ||
@@ -612,3 +647,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) | ||
}, | ||
@@ -645,3 +680,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); | ||
} | ||
@@ -729,3 +764,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: { | ||
@@ -732,0 +767,0 @@ start: protocol_translation_1.toPosition(item.start), |
@@ -27,6 +27,7 @@ "use strict"; | ||
rootUri: null, | ||
publishDiagnostics: args => diagnostics = args | ||
publishDiagnostics: args => diagnostics.push(args) | ||
}); | ||
})); | ||
beforeEach(() => { | ||
diagnostics = []; | ||
server.closeAll(); | ||
@@ -66,3 +67,3 @@ }); | ||
const doc = { | ||
uri: test_utils_1.uri('bar.ts'), | ||
uri: test_utils_1.uri('diagnosticsBar.ts'), | ||
languageId: 'typescript', | ||
@@ -79,11 +80,46 @@ version: 1, | ||
}); | ||
server.requestDiagnostics(); | ||
yield server.requestDiagnostics(); | ||
yield new Promise(resolve => setTimeout(resolve, 200)); | ||
const diagnosticsForThisFile = diagnostics.filter(d => d.uri === doc.uri); | ||
assert.equal(diagnosticsForThisFile.length, 1, JSON.stringify(diagnostics)); | ||
const fileDiagnostics = diagnosticsForThisFile[0].diagnostics; | ||
assert.equal(fileDiagnostics.length, 1); | ||
assert.equal("Cannot find name 'unknown'.", fileDiagnostics[0].message); | ||
})).timeout(10000); | ||
it('multiple files test', () => __awaiter(this, void 0, void 0, function* () { | ||
const doc = { | ||
uri: test_utils_1.uri('multipleFileDiagnosticsBar.ts'), | ||
languageId: 'typescript', | ||
version: 1, | ||
text: ` | ||
export function bar(): void { | ||
unknown('test') | ||
} | ||
` | ||
}; | ||
const doc2 = { | ||
uri: test_utils_1.uri('multipleFileDiagnosticsFoo.ts'), | ||
languageId: 'typescript', | ||
version: 1, | ||
text: ` | ||
export function foo(): void { | ||
unknown('test') | ||
} | ||
` | ||
}; | ||
server.didOpenTextDocument({ | ||
textDocument: doc | ||
}); | ||
server.didOpenTextDocument({ | ||
textDocument: doc2 | ||
}); | ||
yield server.requestDiagnostics(); | ||
yield new Promise(resolve => setTimeout(resolve, 200)); | ||
const diags = diagnostics.diagnostics; | ||
assert.equal(1, diags.length); | ||
assert.equal("Cannot find name 'unknown'.", diags[0].message); | ||
const diagnosticsForThisTest = diagnostics.filter(d => d.uri === doc.uri || d.uri === doc2.uri); | ||
yield new Promise(resolve => setTimeout(resolve, 200)); | ||
assert.equal(diagnosticsForThisTest.length, 2, JSON.stringify(diagnostics)); | ||
})).timeout(10000); | ||
}); | ||
describe('symbol', () => { | ||
describe('document symbol', () => { | ||
it('simple test', () => __awaiter(this, void 0, void 0, function* () { | ||
@@ -115,2 +151,71 @@ const doc = { | ||
})).timeout(10000); | ||
it('merges interfaces correctly', () => __awaiter(this, void 0, void 0, function* () { | ||
const doc = { | ||
uri: test_utils_1.uri('bar.ts'), | ||
languageId: 'typescript', | ||
version: 1, | ||
text: ` | ||
interface Box { | ||
height: number; | ||
width: number; | ||
} | ||
interface Box { | ||
scale: number; | ||
}` | ||
}; | ||
server.didOpenTextDocument({ | ||
textDocument: doc | ||
}); | ||
const symbols = yield server.documentSymbol({ | ||
textDocument: doc, | ||
position: lsp.Position.create(1, 1) | ||
}); | ||
assert.equal(` | ||
Box | ||
height | ||
width | ||
Box | ||
scale | ||
`, symbolsAsString(symbols) + '\n'); | ||
})).timeout(10000); | ||
it('duplication test', () => __awaiter(this, void 0, void 0, function* () { | ||
const doc = { | ||
uri: test_utils_1.uri('bar.ts'), | ||
languageId: 'typescript', | ||
version: 1, | ||
text: ` | ||
export class Foo { | ||
protected foo: string; | ||
public myFunction(arg: string) { | ||
} | ||
} | ||
export class Foo { | ||
protected foo: string; | ||
public myFunction(arg: string) { | ||
} | ||
} | ||
` | ||
}; | ||
server.didOpenTextDocument({ | ||
textDocument: doc | ||
}); | ||
const symbols = yield server.documentSymbol({ | ||
textDocument: doc, | ||
position: lsp.Position.create(1, 1) | ||
}); | ||
const expectation = ` | ||
Foo | ||
foo | ||
myFunction | ||
Foo | ||
foo | ||
myFunction | ||
`; | ||
assert.equal(symbolsAsString(symbols) + '\n', expectation); | ||
assert.deepEqual(symbols[0].selectionRange, { "start": { "line": 1, "character": 21 }, "end": { "line": 1, "character": 24 } }); | ||
assert.deepEqual(symbols[0].range, { "start": { "line": 1, "character": 8 }, "end": { "line": 5, "character": 9 } }); | ||
assert.deepEqual(symbols[1].selectionRange, symbols[1].range); | ||
assert.deepEqual(symbols[1].range, { "start": { "line": 6, "character": 8 }, "end": { "line": 10, "character": 9 } }); | ||
})).timeout(10000); | ||
}); | ||
@@ -136,3 +241,3 @@ function symbolsAsString(symbols, indentation = '') { | ||
const doc = { | ||
uri: test_utils_1.uri('bar.ts'), | ||
uri: test_utils_1.uri('openAndChangeBar.ts'), | ||
languageId: 'typescript', | ||
@@ -163,5 +268,5 @@ version: 1, | ||
yield new Promise(resolve => setTimeout(resolve, 200)); | ||
const diags = diagnostics.diagnostics; | ||
assert.isTrue(diags.length >= 1, diags.map(d => d.message).join(',')); | ||
assert.equal("Cannot find name 'unknown'.", diags[0].message); | ||
const fileDiagnostics = diagnostics.filter(d => d.uri === doc.uri)[0].diagnostics; | ||
assert.isTrue(fileDiagnostics.length >= 1, fileDiagnostics.map(d => d.message).join(',')); | ||
assert.equal("Cannot find name 'unknown'.", fileDiagnostics[0].message); | ||
})).timeout(10000); | ||
@@ -168,0 +273,0 @@ }); |
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 | ||
@@ -195,3 +196,3 @@ }, | ||
function asRange(span) { | ||
return lsp.Range.create(Math.max(0, span.start.line - 1), Math.max(span.start.offset - 1, 0), Math.max(0, span.end.line - 1), Math.max(0, span.end.offset - 1)); | ||
return lsp.Range.create(Math.max(0, span.start.line - 1), Math.max(0, span.start.offset - 1), Math.max(0, span.end.line - 1), Math.max(0, span.end.offset - 1)); | ||
} | ||
@@ -198,0 +199,0 @@ exports.asRange = asRange; |
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; |
@@ -8,7 +8,12 @@ /** | ||
} | ||
export interface TypeScriptPlugin { | ||
name: string; | ||
location: string; | ||
} | ||
export interface TypeScriptInitializationOptions { | ||
logVerbosity?: string; | ||
plugins: TypeScriptPlugin[]; | ||
} | ||
export declare type TypeScriptInitializeParams = lsp.InitializeParams & { | ||
initializationOptions?: TypeScriptInitializationOptions; | ||
initializationOptions?: Partial<TypeScriptInitializationOptions>; | ||
}; | ||
@@ -15,0 +20,0 @@ export interface TypeScriptInitializeResult extends lsp.InitializeResult { |
@@ -10,2 +10,4 @@ import * as protocol from 'typescript/lib/protocol'; | ||
logVerbosity?: string; | ||
globalPlugins?: string[]; | ||
pluginProbeLocations?: string[]; | ||
onEvent?: (event: protocol.Event) => void; | ||
@@ -51,5 +53,3 @@ } | ||
private seq; | ||
private buffer; | ||
private header; | ||
private deferreds; | ||
private readonly deferreds; | ||
private logger; | ||
@@ -56,0 +56,0 @@ private tsserverLogger; |
@@ -20,3 +20,2 @@ "use strict"; | ||
this.seq = 0; | ||
this.buffer = ''; | ||
this.deferreds = {}; | ||
@@ -30,15 +29,20 @@ this.logger = new logger_1.PrefixingLogger(options.logger, '[tsclient]'); | ||
} | ||
const { tsserverPath, logFile, logVerbosity, globalPlugins, pluginProbeLocations } = this.options; | ||
const args = []; | ||
if (this.options.logFile) { | ||
args.push('--logFile'); | ||
args.push(this.options.logFile); | ||
if (logFile) { | ||
args.push('--logFile', logFile); | ||
} | ||
if (this.options.logVerbosity) { | ||
args.push('--logVerbosity'); | ||
args.push(this.options.logVerbosity); | ||
if (logVerbosity) { | ||
args.push('--logVerbosity', logVerbosity); | ||
} | ||
if (globalPlugins && globalPlugins.length) { | ||
args.push('--globalPlugins', globalPlugins.join(',')); | ||
} | ||
if (pluginProbeLocations && pluginProbeLocations.length) { | ||
args.push('--pluginProbeLocations', pluginProbeLocations.join(',')); | ||
} | ||
this.cancellationPipeName = tempy.file({ name: 'tscancellation' }); | ||
args.push('--cancellationPipeName', this.cancellationPipeName + '*'); | ||
this.logger.info(`Starting tsserver : '${this.options.tsserverPath} ${args.join(' ')}'`); | ||
this.tsserverProc = cp.spawn(this.options.tsserverPath, args); | ||
this.logger.info(`Starting tsserver : '${tsserverPath} ${args.join(' ')}'`); | ||
this.tsserverProc = cp.spawn(tsserverPath, args); | ||
this.readlineInterface = readline.createInterface(this.tsserverProc.stdout, this.tsserverProc.stdin, undefined); | ||
@@ -45,0 +49,0 @@ process.on('exit', () => { |
{ | ||
"name": "typescript-language-server", | ||
"version": "0.4.0-dev.a1b151f", | ||
"version": "0.4.0-dev.b361793", | ||
"description": "Language Server Protocol (LSP) implementation for TypeScript using tsserver", | ||
@@ -37,3 +37,3 @@ "author": "TypeFox and others", | ||
}, | ||
"gitHead": "a1b151f54885208f92e13aa18b385d08a63bf61c" | ||
"gitHead": "b3617931417ca190fea1784ab74ed2f594a0c80c" | ||
} |
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
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
263955
3440
6