diff --git a/.eslintrc.cjs b/.eslintrc.cjs index ebb14515..0afd4b45 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -14,7 +14,7 @@ module.exports = { rules: { 'array-bracket-spacing': 'error', 'brace-style': 'error', - 'comma-dangle': 'error', + 'comma-dangle': ['error', 'always-multiline'], 'comma-spacing': 'error', 'computed-property-spacing': 'error', curly: 'error', diff --git a/package.json b/package.json index 67b1565d..4815e626 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "test:watch": "cross-env CONSOLE_LOG_LEVEL=warn TS_NODE_PROJECT=./tsconfig.json mocha --watch", "test:compiled": "cross-env CONSOLE_LOG_LEVEL=warn mocha \"./lib/**/*.spec.js\"", "lint": "eslint --ext \".js,.ts\" src", + "fix": "eslint --ext \".js,.ts\" --fix src", "build": "concurrently -n compile,lint -c blue,green \"yarn compile\" \"yarn lint\"", "compile": "tsc -b", "watch": "tsc -b --watch --verbose", diff --git a/src/calls.ts b/src/calls.ts index a348a0b5..3ec67b5e 100644 --- a/src/calls.ts +++ b/src/calls.ts @@ -28,7 +28,7 @@ export async function computeCallers(tspClient: TspClient, args: lsp.TextDocumen const location = toLocation(callerReference, undefined); calls.push({ location, - symbol + symbol, }); } return { calls, symbol: contextSymbol }; @@ -59,7 +59,7 @@ export async function computeCallees(tspClient: TspClient, args: lsp.TextDocumen const location = toLocation(reference, undefined); calls.push({ location, - symbol: definitionSymbol + symbol: definitionSymbol, }); } return { calls, symbol: contextSymbol }; @@ -128,7 +128,7 @@ async function getDefinition(tspClient: TspClient, args: lsp.TextDocumentPositio const definitionResult = await tspClient.request(CommandTypes.Definition, { file, line: args.position.line + 1, - offset: args.position.character + 1 + offset: args.position.character + 1, }); return definitionResult.body ? definitionResult.body[0] : undefined; } @@ -180,7 +180,7 @@ function findEnclosingSymbolInTree(parent: tsp.NavigationTree, range: lsp.Range) name: candidate.text, kind: toSymbolKind(candidate.kind), range: spanRange, - selectionRange: selectionRange + selectionRange: selectionRange, }; } @@ -197,7 +197,7 @@ async function findReferences(tspClient: TspClient, args: tsp.FileSpan): Promise const result = await tspClient.request(CommandTypes.References, { file, line: args.start.line, - offset: args.start.offset + offset: args.start.offset, }); if (!result.body) { return []; diff --git a/src/cli.ts b/src/cli.ts index 9fec780d..8ed86f0d 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -43,5 +43,5 @@ createLspConnection({ tsserverPath: options.tsserverPath as string, tsserverLogFile: options.tsserverLogFile as string, tsserverLogVerbosity: options.tsserverLogVerbosity as string, - showMessageLevel: logLevel as lsp.MessageType + showMessageLevel: logLevel as lsp.MessageType, }).listen(); diff --git a/src/commands.ts b/src/commands.ts index ef04c370..abc40634 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -16,5 +16,5 @@ export const Commands = { APPLY_COMPLETION_CODE_ACTION: '_typescript.applyCompletionCodeAction', /** Commands below should be implemented by the client */ SELECT_REFACTORING: '_typescript.selectRefactoring', - SOURCE_DEFINITION: SourceDefinitionCommand.id + SOURCE_DEFINITION: SourceDefinitionCommand.id, }; diff --git a/src/completion.ts b/src/completion.ts index 560c3bb4..cb50ea4a 100644 --- a/src/completion.ts +++ b/src/completion.ts @@ -38,10 +38,10 @@ export function asCompletionItem(entry: tsp.CompletionEntry, file: string, posit entry.source || entry.data ? { name: entry.name, source: entry.source, - data: entry.data - } : entry.name - ] - } + data: entry.data, + } : entry.name, + ], + }, }; if (entry.source && entry.hasAction) { @@ -192,7 +192,7 @@ function asCommitCharacters(kind: ScriptElementKind): string[] | undefined { } export async function asResolvedCompletionItem( - item: lsp.CompletionItem, details: tsp.CompletionEntryDetails, client: TspClient, options: WorkspaceConfigurationCompletionOptions, features: SupportedFeatures + item: lsp.CompletionItem, details: tsp.CompletionEntryDetails, client: TspClient, options: WorkspaceConfigurationCompletionOptions, features: SupportedFeatures, ): Promise { item.detail = asDetail(details); item.documentation = asDocumentation(details); @@ -364,8 +364,8 @@ function asCommand(codeActions: tsp.CodeAction[], filepath: string): lsp.Command arguments: [filepath, codeActions.map(codeAction => ({ commands: codeAction.commands, description: codeAction.description, - changes: codeAction.changes.filter(x => x.fileName !== filepath) - }))] + changes: codeAction.changes.filter(x => x.fileName !== filepath), + }))], }; } } diff --git a/src/configuration-manager.ts b/src/configuration-manager.ts index 27e60078..222a328c 100644 --- a/src/configuration-manager.ts +++ b/src/configuration-manager.ts @@ -36,7 +36,7 @@ const DEFAULT_TSSERVER_PREFERENCES: Required = { providePrefixAndSuffixTextForRename: true, provideRefactorNotApplicableReason: false, quotePreference: 'auto', - useLabelDetailsInCompletionEntries: true + useLabelDetailsInCompletionEntries: true, }; export interface WorkspaceConfiguration { @@ -88,12 +88,12 @@ export class ConfigurationManager { this.tspClient = client; const formatOptions: tsp.FormatCodeSettings = { // We can use \n here since the editor should normalize later on to its line endings. - newLineCharacter: '\n' + newLineCharacter: '\n', }; const args: tsp.ConfigureRequestArguments = { ...hostInfo ? { hostInfo } : {}, formatOptions, - preferences: this.tsPreferences + preferences: this.tsPreferences, }; await this.tspClient?.request(CommandTypes.Configure, args); } @@ -101,7 +101,7 @@ export class ConfigurationManager { public async configureGloballyFromDocument(filename: string, formattingOptions?: lsp.FormattingOptions): Promise { const args: tsp.ConfigureRequestArguments = { formatOptions: this.getFormattingOptions(filename, formattingOptions), - preferences: this.getPreferences(filename) + preferences: this.getPreferences(filename), }; await this.tspClient?.request(CommandTypes.Configure, args); } @@ -115,12 +115,12 @@ export class ConfigurationManager { const preferences = Object.assign( {}, this.tsPreferences, - workspacePreferences?.inlayHints || {} + workspacePreferences?.inlayHints || {}, ); return { ...preferences, - quotePreference: this.getQuoteStylePreference(preferences) + quotePreference: this.getQuoteStylePreference(preferences), }; } @@ -129,7 +129,7 @@ export class ConfigurationManager { const opts: tsp.FormatCodeSettings = { ...workspacePreferences?.format, - ...formattingOptions + ...formattingOptions, }; if (opts.convertTabsToSpaces === undefined) { diff --git a/src/diagnostic-queue.ts b/src/diagnostic-queue.ts index 71859b45..082d2eb2 100644 --- a/src/diagnostic-queue.ts +++ b/src/diagnostic-queue.ts @@ -21,7 +21,7 @@ class FileDiagnostics { protected readonly uri: string, protected readonly publishDiagnostics: (params: lsp.PublishDiagnosticsParams) => void, protected readonly documents: LspDocuments, - protected readonly features: SupportedFeatures + protected readonly features: SupportedFeatures, ) { } update(kind: EventTypes, diagnostics: tsp.Diagnostic[]): void { @@ -52,7 +52,7 @@ export class DiagnosticEventQueue { protected readonly publishDiagnostics: (params: lsp.PublishDiagnosticsParams) => void, protected readonly documents: LspDocuments, protected readonly features: SupportedFeatures, - protected readonly logger: Logger + protected readonly logger: Logger, ) { } updateDiagnostics(kind: EventTypes, event: tsp.DiagnosticEvent): void { diff --git a/src/document-symbol.ts b/src/document-symbol.ts index 00b4ccb6..b0087c78 100644 --- a/src/document-symbol.ts +++ b/src/document-symbol.ts @@ -48,7 +48,7 @@ function collectDocumentSymbolsInRange(parent: tsp.NavigationTree, symbols: lsp. kind: toSymbolKind(parent.kind), range: spanRange, selectionRange: selectionRange, - children + children, }); } } @@ -76,9 +76,9 @@ export function collectSymbolInformation(uri: string, current: tsp.NavigationTre kind: toSymbolKind(current.kind), location: { uri, - range + range, }, - containerName + containerName, }); symbols.push(...children); } diff --git a/src/features/fix-all.ts b/src/features/fix-all.ts index ef3ebc42..c17d6eaf 100644 --- a/src/features/fix-all.ts +++ b/src/features/fix-all.ts @@ -24,7 +24,7 @@ async function buildIndividualFixes( client: TspClient, file: string, documents: LspDocuments, - diagnostics: readonly lsp.Diagnostic[] + diagnostics: readonly lsp.Diagnostic[], ): Promise { const edits: lsp.TextDocumentEdit[] = []; for (const diagnostic of diagnostics) { @@ -35,7 +35,7 @@ async function buildIndividualFixes( const args: tsp.CodeFixRequestArgs = { ...Range.toFileRangeRequestArgs(file, diagnostic.range), - errorCodes: [+diagnostic.code!] + errorCodes: [+diagnostic.code!], }; const response = await client.request(CommandTypes.GetCodeFixes, args); @@ -58,7 +58,7 @@ async function buildCombinedFix( client: TspClient, file: string, documents: LspDocuments, - diagnostics: readonly lsp.Diagnostic[] + diagnostics: readonly lsp.Diagnostic[], ): Promise { const edits: lsp.TextDocumentEdit[] = []; for (const diagnostic of diagnostics) { @@ -69,7 +69,7 @@ async function buildCombinedFix( const args: tsp.CodeFixRequestArgs = { ...Range.toFileRangeRequestArgs(file, diagnostic.range), - errorCodes: [+diagnostic.code!] + errorCodes: [+diagnostic.code!], }; const response = await client.request(CommandTypes.GetCodeFixes, args); @@ -90,9 +90,9 @@ async function buildCombinedFix( const combinedArgs: tsp.GetCombinedCodeFixRequestArgs = { scope: { type: 'file', - args: { file } + args: { file }, }, - fixId: fix.fixId + fixId: fix.fixId, }; const combinedResponse = await client.request(CommandTypes.GetCombinedCodeFix, combinedArgs); @@ -126,15 +126,15 @@ class SourceFixAll extends SourceAction { client: TspClient, file: string, documents: LspDocuments, - diagnostics: readonly lsp.Diagnostic[] + diagnostics: readonly lsp.Diagnostic[], ): Promise { const edits: lsp.TextDocumentEdit[] = []; edits.push(...await buildIndividualFixes([ { codes: errorCodes.incorrectlyImplementsInterface, fixName: fixNames.classIncorrectlyImplementsInterface }, - { codes: errorCodes.asyncOnlyAllowedInAsyncFunctions, fixName: fixNames.awaitInSyncFunction } + { codes: errorCodes.asyncOnlyAllowedInAsyncFunctions, fixName: fixNames.awaitInSyncFunction }, ], client, file, documents, diagnostics)); edits.push(...await buildCombinedFix([ - { codes: errorCodes.unreachableCode, fixName: fixNames.unreachableCode } + { codes: errorCodes.unreachableCode, fixName: fixNames.unreachableCode }, ], client, file, documents, diagnostics)); if (!edits.length) { return null; @@ -151,10 +151,10 @@ class SourceRemoveUnused extends SourceAction { client: TspClient, file: string, documents: LspDocuments, - diagnostics: readonly lsp.Diagnostic[] + diagnostics: readonly lsp.Diagnostic[], ): Promise { const edits = await buildCombinedFix([ - { codes: errorCodes.variableDeclaredButNeverUsed, fixName: fixNames.unusedIdentifier } + { codes: errorCodes.variableDeclaredButNeverUsed, fixName: fixNames.unusedIdentifier }, ], client, file, documents, diagnostics); if (!edits.length) { return null; @@ -171,10 +171,10 @@ class SourceAddMissingImports extends SourceAction { client: TspClient, file: string, documents: LspDocuments, - diagnostics: readonly lsp.Diagnostic[] + diagnostics: readonly lsp.Diagnostic[], ): Promise { const edits = await buildCombinedFix([ - { codes: errorCodes.cannotFindName, fixName: fixNames.fixImport } + { codes: errorCodes.cannotFindName, fixName: fixNames.fixImport }, ], client, file, documents, diagnostics); if (!edits.length) { return null; @@ -189,7 +189,7 @@ export class TypeScriptAutoFixProvider { private static kindProviders = [ SourceFixAll, SourceRemoveUnused, - SourceAddMissingImports + SourceAddMissingImports, ]; public static get kinds(): CodeActionKind[] { diff --git a/src/features/inlay-hints.ts b/src/features/inlay-hints.ts index 5de8b5b1..e4fb1795 100644 --- a/src/features/inlay-hints.ts +++ b/src/features/inlay-hints.ts @@ -29,7 +29,7 @@ export class TypeScriptInlayHintsProvider { documents: LspDocuments, tspClient: TspClient, lspClient: LspClient, - configurationManager: ConfigurationManager + configurationManager: ConfigurationManager, ): Promise { if (tspClient.apiVersion.lt(TypeScriptInlayHintsProvider.minVersion)) { lspClient.showErrorMessage('Inlay Hints request failed. Requires TypeScript 4.4+.'); diff --git a/src/features/source-definition.ts b/src/features/source-definition.ts index 1bd61d85..51a5df50 100644 --- a/src/features/source-definition.ts +++ b/src/features/source-definition.ts @@ -28,7 +28,7 @@ export class SourceDefinitionCommand { documents: LspDocuments, tspClient: TspClient, lspClient: LspClient, - reporter: lsp.WorkDoneProgressReporter + reporter: lsp.WorkDoneProgressReporter, ): Promise { if (tspClient.apiVersion.lt(SourceDefinitionCommand.minVersion)) { lspClient.showErrorMessage('Go to Source Definition failed. Requires TypeScript 4.7+.'); @@ -57,7 +57,7 @@ export class SourceDefinitionCommand { const args = Position.toFileLocationRequestArgs(file, position); return await lspClient.withProgress({ message: 'Finding source definitions…', - reporter + reporter, }, async () => { const response = await tspClient.request(CommandTypes.FindSourceDefinition, args); if (response.type === 'response' && response.body?.length) { diff --git a/src/file-lsp-server.spec.ts b/src/file-lsp-server.spec.ts index 13b78403..0ab0ed8b 100644 --- a/src/file-lsp-server.spec.ts +++ b/src/file-lsp-server.spec.ts @@ -16,7 +16,7 @@ let server: LspServer; before(async () => { server = await createServer({ rootUri: uri(), - publishDiagnostics: () => { } + publishDiagnostics: () => { }, }); }); @@ -35,15 +35,15 @@ describe('documentHighlight', () => { uri: uri('module2.ts'), languageId: 'typescript', version: 1, - text: readContents(filePath('module2.ts')) + text: readContents(filePath('module2.ts')), }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); const result = await server.documentHighlight({ textDocument: doc, - position: lastPosition(doc, 'doStuff') + position: lastPosition(doc, 'doStuff'), }); assert.equal(2, result.length, JSON.stringify(result, undefined, 2)); }); @@ -55,12 +55,12 @@ describe('completions', () => { uri: uri('completion.ts'), languageId: 'typescript', version: 1, - text: readContents(filePath('completion.ts')) + text: readContents(filePath('completion.ts')), }; server.didOpenTextDocument({ textDocument: doc }); const proposals = await server.completion({ textDocument: doc, - position: positionAfter(doc, 'doStuff') + position: positionAfter(doc, 'doStuff'), }); assert.isNotNull(proposals); const completion = proposals!.items.find(item => item.label === 'doStuff'); diff --git a/src/hover.ts b/src/hover.ts index 3f073f86..361218f3 100644 --- a/src/hover.ts +++ b/src/hover.ts @@ -18,7 +18,7 @@ export function asSignatureHelp(info: tsp.SignatureHelpItems, context?: lsp.Sign return { activeSignature: getActiveSignature(info, signatures, context), activeParameter: getActiveParameter(info), - signatures + signatures, }; } @@ -51,9 +51,9 @@ function asSignatureInformation(item: tsp.SignatureHelpItem): lsp.SignatureInfor label: asPlainText(item.prefixDisplayParts), documentation: asDocumentation({ documentation: item.documentation, - tags: item.tags.filter(x => x.name !== 'param') + tags: item.tags.filter(x => x.name !== 'param'), }), - parameters + parameters, }; signature.label += parameters.map(parameter => parameter.label).join(asPlainText(item.separatorDisplayParts)); signature.label += asPlainText(item.suffixDisplayParts); @@ -63,7 +63,7 @@ function asSignatureInformation(item: tsp.SignatureHelpItem): lsp.SignatureInfor function asParameterInformation(parameter: tsp.SignatureHelpParameter): lsp.ParameterInformation { return { label: asPlainText(parameter.displayParts), - documentation: asDocumentation(parameter) + documentation: asDocumentation(parameter), }; } diff --git a/src/logger.ts b/src/logger.ts index e7726af1..dcb4fc38 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -33,7 +33,7 @@ export class LspClientLogger implements Logger { this.client.logMessage({ type: severity, - message: message + message: message, }); } } diff --git a/src/lsp-connection.ts b/src/lsp-connection.ts index 6a3f7d62..92e0cab6 100644 --- a/src/lsp-connection.ts +++ b/src/lsp-connection.ts @@ -28,7 +28,7 @@ export function createLspConnection(options: IServerOptions): lsp.Connection { lspClient, tsserverPath: options.tsserverPath, tsserverLogFile: options.tsserverLogFile, - tsserverLogVerbosity: options.tsserverLogVerbosity + tsserverLogVerbosity: options.tsserverLogVerbosity, }); connection.onInitialize(server.initialize.bind(server)); diff --git a/src/lsp-server.spec.ts b/src/lsp-server.spec.ts index e39502d5..668ee67d 100644 --- a/src/lsp-server.spec.ts +++ b/src/lsp-server.spec.ts @@ -23,14 +23,14 @@ let server: TestLspServer; before(async () => { server = await createServer({ rootUri: uri(), - publishDiagnostics: args => diagnostics.set(args.uri, args) + publishDiagnostics: args => diagnostics.set(args.uri, args), }); server.didChangeConfiguration({ settings: { completions: { - completeFunctionCalls: true - } - } + completeFunctionCalls: true, + }, + }, }); }); @@ -56,10 +56,10 @@ describe('completion', () => { export function foo(): void { console.log('test') } - ` + `, }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); const pos = position(doc, 'console'); const proposals = await server.completion({ textDocument: doc, position: pos }); @@ -82,10 +82,10 @@ describe('completion', () => { export function foo() { console.log('test') } - ` + `, }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); const pos = position(doc, 'console'); const proposals = await server.completion({ textDocument: doc, position: pos }); @@ -125,10 +125,10 @@ describe('completion', () => { } foo(); // call me - ` + `, }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); const pos = position(doc, 'foo(); // call me'); const proposals = await server.completion({ textDocument: doc, position: pos }); @@ -151,10 +151,10 @@ describe('completion', () => { export function foo(): void { console.log('test') } - ` + `, }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); const pos = position(doc, 'foo'); const proposals = await server.completion({ textDocument: doc, position: pos }); @@ -167,7 +167,7 @@ describe('completion', () => { uri: uri('bar.ts'), languageId: 'typescript', version: 1, - text: 'pathex' + text: 'pathex', }; server.didOpenTextDocument({ textDocument: doc }); const proposals = await server.completion({ textDocument: doc, position: position(doc, 'ex') }); @@ -189,7 +189,7 @@ describe('completion', () => { const foo: Foo foo.i - ` + `, }; server.didOpenTextDocument({ textDocument: doc }); const proposals = await server.completion({ textDocument: doc, position: positionAfter(doc, '.i') }); @@ -206,7 +206,7 @@ describe('completion', () => { uri: uri('bar.ts'), languageId: 'typescript', version: 1, - text: 'readFile' + text: 'readFile', }; server.didOpenTextDocument({ textDocument: doc }); const proposals = await server.completion({ textDocument: doc, position: positionAfter(doc, 'readFile') }); @@ -223,7 +223,7 @@ describe('completion', () => { uri: uri('bar.ts'), languageId: 'typescript', version: 1, - text: 'readFile' + text: 'readFile', }; server.didOpenTextDocument({ textDocument: doc }); const proposals = await server.completion({ textDocument: doc, position: positionAfter(doc, 'readFile') }); @@ -237,14 +237,14 @@ describe('completion', () => { range: { end: { character: 0, - line: 0 + line: 0, }, start: { character: 0, - line: 0 - } - } - } + line: 0, + }, + }, + }, ]); server.didCloseTextDocument({ textDocument: doc }); }); @@ -255,17 +255,17 @@ describe('completion', () => { typescript: { format: { semicolons: 'remove', - insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: false - } - } - } + insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: false, + }, + }, + }, }); const doc = { uri: uri('bar.ts'), languageId: 'typescript', version: 1, - text: 'readFile' + text: 'readFile', }; server.didOpenTextDocument({ textDocument: doc }); const proposals = await server.completion({ textDocument: doc, position: positionAfter(doc, 'readFile') }); @@ -279,28 +279,28 @@ describe('completion', () => { range: { end: { character: 0, - line: 0 + line: 0, }, start: { character: 0, - line: 0 - } - } - } + line: 0, + }, + }, + }, ]); server.didCloseTextDocument({ textDocument: doc }); server.didChangeConfiguration({ settings: { completions: { - completeFunctionCalls: true + completeFunctionCalls: true, }, typescript: { format: { semicolons: 'ignore', - insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true - } - } - } + insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true, + }, + }, + }, }); }); @@ -312,7 +312,7 @@ describe('completion', () => { text: ` import fs from 'fs' fs.readFile - ` + `, }; server.didOpenTextDocument({ textDocument: doc }); const proposals = await server.completion({ textDocument: doc, position: positionAfter(doc, 'readFile') }); @@ -338,7 +338,7 @@ describe('completion', () => { } test("fs/") - ` + `, }; server.didOpenTextDocument({ textDocument: doc }); const proposals = await server.completion({ @@ -346,8 +346,8 @@ describe('completion', () => { position: positionAfter(doc, 'test("fs/'), context: { triggerCharacter: '/', - triggerKind: 2 - } + triggerKind: 2, + }, }); assert.isNotNull(proposals); const completion = proposals!.items.find(completion => completion.label === 'fs/read'); @@ -355,9 +355,9 @@ describe('completion', () => { assert.deepStrictEqual(completion!.textEdit, { range: { start: { line: 5, character: 20 }, - end: { line: 5, character: 23 } + end: { line: 5, character: 23 }, }, - newText: 'fs/read' + newText: 'fs/read', }); }); @@ -373,12 +373,12 @@ describe('completion', () => { const obj: IFoo = { /*a*/ } - ` + `, }; server.didOpenTextDocument({ textDocument: doc }); const proposals = await server.completion({ textDocument: doc, - position: positionAfter(doc, '/*a*/') + position: positionAfter(doc, '/*a*/'), }); assert.isNotNull(proposals); assert.lengthOf(proposals!.items, 2); @@ -387,20 +387,20 @@ describe('completion', () => { { label: 'bar', kind: 2, - insertTextFormat: 2 - } + insertTextFormat: 2, + }, ); assert.deepInclude( proposals!.items[1], { label: 'bar', labelDetails: { - detail: '(x)' + detail: '(x)', }, kind: 2, insertTextFormat: 2, - insertText: toPlatformEOL('bar(x) {\n $0\n},') - } + insertText: toPlatformEOL('bar(x) {\n $0\n},'), + }, ); }); }); @@ -413,12 +413,12 @@ describe('definition', () => { uri: indexUri, languageId: 'typescript', version: 1, - text: readContents(filePath('source-definition', 'index.ts')) + text: readContents(filePath('source-definition', 'index.ts')), }; server.didOpenTextDocument({ textDocument: indexDoc }); const definitions = await server.definition({ textDocument: indexDoc, - position: position(indexDoc, 'a/*identifier*/') + position: position(indexDoc, 'a/*identifier*/'), }) as lsp.Location[]; assert.isArray(definitions); assert.equal(definitions!.length, 1); @@ -427,13 +427,13 @@ describe('definition', () => { range: { start: { line: 0, - character: 21 + character: 21, }, end: { line: 0, - character: 22 - } - } + character: 22, + }, + }, }); }); }); @@ -445,14 +445,14 @@ describe('definition (definition link supported)', () => { const clientCapabilitiesOverride: lsp.ClientCapabilities = { textDocument: { definition: { - linkSupport: true - } - } + linkSupport: true, + }, + }, }; localServer = await createServer({ rootUri: uri('source-definition'), publishDiagnostics: args => diagnostics.set(args.uri, args), - clientCapabilitiesOverride + clientCapabilitiesOverride, }); }); @@ -475,12 +475,12 @@ describe('definition (definition link supported)', () => { uri: indexUri, languageId: 'typescript', version: 1, - text: readContents(filePath('source-definition', 'index.ts')) + text: readContents(filePath('source-definition', 'index.ts')), }; localServer.didOpenTextDocument({ textDocument: indexDoc }); const definitions = await localServer.definition({ textDocument: indexDoc, - position: position(indexDoc, 'a/*identifier*/') + position: position(indexDoc, 'a/*identifier*/'), }) as lsp.DefinitionLink[]; assert.isArray(definitions); assert.equal(definitions!.length, 1); @@ -488,34 +488,34 @@ describe('definition (definition link supported)', () => { originSelectionRange: { start: { line: 1, - character: 0 + character: 0, }, end: { line: 1, - character: 1 - } + character: 1, + }, }, targetRange: { start: { line: 0, - character: 0 + character: 0, }, end: { line: 0, - character: 30 - } + character: 30, + }, }, targetUri: uri('source-definition', 'a.d.ts'), targetSelectionRange: { start: { line: 0, - character: 21 + character: 21, }, end: { line: 0, - character: 22 - } - } + character: 22, + }, + }, }); }); }); @@ -530,10 +530,10 @@ describe('diagnostics', () => { export function foo(): void { missing('test') } - ` + `, }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); await server.requestDiagnostics(); @@ -556,10 +556,10 @@ describe('diagnostics', () => { /** @deprecated */ function foo(): void {} foo(); - ` + `, }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); await server.requestDiagnostics(); @@ -585,7 +585,7 @@ describe('diagnostics', () => { export function bar(): void { missing('test') } -` +`, }; const doc2 = { uri: uri('multipleFileDiagnosticsFoo.ts'), @@ -595,13 +595,13 @@ describe('diagnostics', () => { export function foo(): void { missing('test') } -` +`, }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); server.didOpenTextDocument({ - textDocument: doc2 + textDocument: doc2, }); await server.requestDiagnostics(); @@ -619,9 +619,9 @@ describe('diagnostics', () => { server.didChangeConfiguration({ settings: { diagnostics: { - ignoredCodes: [6133] - } - } + ignoredCodes: [6133], + }, + }, }); const doc = { @@ -633,10 +633,10 @@ describe('diagnostics', () => { const x = 42; return 1; } - ` + `, }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); await server.requestDiagnostics(); @@ -660,10 +660,10 @@ describe('document symbol', () => { public myFunction(arg: string) { } } - ` + `, }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); const symbols = await server.documentSymbol({ textDocument: doc }); assert.equal(` @@ -686,10 +686,10 @@ interface Box { interface Box { scale: number; -}` +}`, }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); const symbols = await server.documentSymbol({ textDocument: doc }); assert.equal(` @@ -717,10 +717,10 @@ Box public myFunction(arg: string) { } } - ` + `, }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); const symbols = await server.documentSymbol({ textDocument: doc }) as lsp.DocumentSymbol[]; const expectation = ` @@ -765,10 +765,10 @@ describe('editing', () => { text: ` export function foo(): void { } - ` + `, }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); server.didChangeTextDocument({ textDocument: doc, @@ -778,9 +778,9 @@ describe('editing', () => { export function foo(): void { missing('test'); } - ` - } - ] + `, + }, + ], }); await server.requestDiagnostics(); await new Promise(resolve => setTimeout(resolve, 200)); @@ -801,17 +801,17 @@ describe('references', () => { text: ` function foo() {}; foo(); - ` + `, }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); // Without declaration/definition. const position = lastPosition(doc, 'function foo()'); let references = await server.references({ context: { includeDeclaration: false }, textDocument: doc, - position + position, }); assert.strictEqual(references.length, 1); assert.strictEqual(references[0].range.start.line, 2); @@ -819,7 +819,7 @@ describe('references', () => { references = await server.references({ context: { includeDeclaration: true }, textDocument: doc, - position + position, }); assert.strictEqual(references.length, 2); }); @@ -870,15 +870,15 @@ describe('formatting', () => { it('full document formatting', async () => { const text = 'export function foo ( ) : void { }'; const textDocument = { - uri: uriString, languageId, version, text + uri: uriString, languageId, version, text, }; server.didOpenTextDocument({ textDocument }); const edits = await server.documentFormatting({ textDocument, options: { tabSize: 4, - insertSpaces: true - } + insertSpaces: true, + }, }); const result = TextDocument.applyEdits(TextDocument.create(uriString, languageId, version, text), edits); assert.equal('export function foo(): void { }', result); @@ -887,15 +887,15 @@ describe('formatting', () => { it('indent settings (3 spaces)', async () => { const text = 'function foo() {\n// some code\n}'; const textDocument = { - uri: uriString, languageId, version, text + uri: uriString, languageId, version, text, }; server.didOpenTextDocument({ textDocument }); const edits = await server.documentFormatting({ textDocument, options: { tabSize: 3, - insertSpaces: true - } + insertSpaces: true, + }, }); const result = TextDocument.applyEdits(TextDocument.create(uriString, languageId, version, text), edits); assert.equal('function foo() {\n // some code\n}', result); @@ -904,15 +904,15 @@ describe('formatting', () => { it('indent settings (tabs)', async () => { const text = 'function foo() {\n// some code\n}'; const textDocument = { - uri: uriString, languageId, version, text + uri: uriString, languageId, version, text, }; server.didOpenTextDocument({ textDocument }); const edits = await server.documentFormatting({ textDocument, options: { tabSize: 4, - insertSpaces: false - } + insertSpaces: false, + }, }); const result = TextDocument.applyEdits(TextDocument.create(uriString, languageId, version, text), edits); assert.equal('function foo() {\n\t// some code\n}', result); @@ -921,7 +921,7 @@ describe('formatting', () => { it('formatting setting set through workspace configuration', async () => { const text = 'function foo() {\n// some code\n}'; const textDocument = { - uri: uriString, languageId, version, text + uri: uriString, languageId, version, text, }; server.didOpenTextDocument({ textDocument }); @@ -930,18 +930,18 @@ describe('formatting', () => { typescript: { format: { newLineCharacter: '\n', - placeOpenBraceOnNewLineForFunctions: true - } - } - } + placeOpenBraceOnNewLineForFunctions: true, + }, + }, + }, }); const edits = await server.documentFormatting({ textDocument, options: { tabSize: 4, - insertSpaces: false - } + insertSpaces: false, + }, }); const result = TextDocument.applyEdits(TextDocument.create(uriString, languageId, version, text), edits); assert.equal('function foo()\n{\n\t// some code\n}', result); @@ -950,7 +950,7 @@ describe('formatting', () => { it('selected range', async () => { const text = 'function foo() {\nconst first = 1;\nconst second = 2;\nconst val = foo( "something" );\n//const fourth = 4;\n}'; const textDocument = { - uri: uriString, languageId, version, text + uri: uriString, languageId, version, text, }; server.didOpenTextDocument({ textDocument }); const edits = await server.documentRangeFormatting({ @@ -958,17 +958,17 @@ describe('formatting', () => { range: { start: { line: 2, - character: 0 + character: 0, }, end: { line: 3, - character: 30 - } + character: 30, + }, }, options: { tabSize: 4, - insertSpaces: true - } + insertSpaces: true, + }, }); const result = TextDocument.applyEdits(TextDocument.create(uriString, languageId, version, text), edits); assert.equal('function foo() {\nconst first = 1;\n const second = 2;\n const val = foo("something");\n//const fourth = 4;\n}', result); @@ -985,14 +985,14 @@ describe('signatureHelp', () => { export function foo(bar: string, baz?:boolean): void {} export function foo(n: number, baz?: boolean): void foo(param1, param2) - ` + `, }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); let result = (await server.signatureHelp({ textDocument: doc, - position: position(doc, 'param1') + position: position(doc, 'param1'), }))!; assert.equal(result.signatures.length, 2); @@ -1001,7 +1001,7 @@ describe('signatureHelp', () => { result = (await server.signatureHelp({ textDocument: doc, - position: position(doc, 'param2') + position: position(doc, 'param2'), }))!; assert.equal('baz?: boolean', result.signatures[result.activeSignature!].parameters![result.activeParameter!].label); @@ -1016,12 +1016,12 @@ describe('signatureHelp', () => { export function foo(bar: string, baz?: boolean): void {} export function foo(n: number, baz?: boolean): void foo(param1, param2) - ` + `, }; server.didOpenTextDocument({ textDocument: doc }); let result = await server.signatureHelp({ textDocument: doc, - position: position(doc, 'param1') + position: position(doc, 'param1'), }); assert.equal(result!.signatures.length, 2); @@ -1033,14 +1033,14 @@ describe('signatureHelp', () => { triggerKind: lsp.SignatureHelpTriggerKind.Invoked, activeSignatureHelp: { signatures: result!.signatures, - activeSignature: 1 // select second signature - } - } + activeSignature: 1, // select second signature + }, + }, }))!; const { activeSignature, signatures } = result!; assert.equal(activeSignature, 1); assert.deepInclude(signatures[activeSignature!], { - label: 'foo(n: number, baz?: boolean): void' + label: 'foo(n: number, baz?: boolean): void', }); }); }); @@ -1053,29 +1053,29 @@ describe('code actions', () => { text: `import { something } from "something"; export function foo(bar: string, baz?:boolean): void {} foo(param1, param2) - ` + `, }; it('can provide quickfix code actions', async () => { server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); const result = (await server.codeAction({ textDocument: doc, range: { start: { line: 1, character: 25 }, - end: { line: 1, character: 49 } + end: { line: 1, character: 49 }, }, context: { diagnostics: [{ range: { start: { line: 1, character: 25 }, - end: { line: 1, character: 49 } + end: { line: 1, character: 49 }, }, code: 6133, - message: 'unused arg' - }] - } + message: 'unused arg', + }], + }, }))!; assert.strictEqual(result.length, 2); @@ -1092,29 +1092,29 @@ describe('code actions', () => { { textDocument: { uri: uri('bar.ts'), - version: 1 + version: 1, }, edits: [ { range: { start: { line: 1, - character: 24 + character: 24, }, end: { line: 1, - character: 27 - } + character: 27, + }, }, - newText: '_bar' - } - ] - } - ] - } - ] + newText: '_bar', + }, + ], + }, + ], + }, + ], }, - kind: 'quickfix' + kind: 'quickfix', }); const refactorDiagnostic = result.find(diagnostic => diagnostic.kind === 'refactor'); assert.isDefined(refactorDiagnostic); @@ -1131,35 +1131,35 @@ describe('code actions', () => { endLine: 2, endOffset: 50, refactor: 'Convert parameters to destructured object', - action: 'Convert parameters to destructured object' - } - ] + action: 'Convert parameters to destructured object', + }, + ], }, - kind: 'refactor' + kind: 'refactor', }); }); it('can filter quickfix code actions filtered by only', async () => { server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); const result = (await server.codeAction({ textDocument: doc, range: { start: { line: 1, character: 25 }, - end: { line: 1, character: 49 } + end: { line: 1, character: 49 }, }, context: { diagnostics: [{ range: { start: { line: 1, character: 25 }, - end: { line: 1, character: 49 } + end: { line: 1, character: 49 }, }, code: 6133, - message: 'unused arg' + message: 'unused arg', }], - only: ['refactor', 'invalid-action'] - } + only: ['refactor', 'invalid-action'], + }, }))!; assert.deepEqual(result, [ @@ -1173,21 +1173,21 @@ describe('code actions', () => { file: filePath('bar.ts'), refactor: 'Convert parameters to destructured object', startLine: 2, - startOffset: 26 - } + startOffset: 26, + }, ], command: '_typescript.applyRefactoring', - title: 'Convert parameters to destructured object' + title: 'Convert parameters to destructured object', }, kind: 'refactor', - title: 'Convert parameters to destructured object' - } + title: 'Convert parameters to destructured object', + }, ]); }); it('does not provide organize imports when there are errors', async () => { server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); await server.requestDiagnostics(); await new Promise(resolve => setTimeout(resolve, 200)); @@ -1195,19 +1195,19 @@ describe('code actions', () => { textDocument: doc, range: { start: { line: 1, character: 29 }, - end: { line: 1, character: 53 } + end: { line: 1, character: 53 }, }, context: { diagnostics: [{ range: { start: { line: 1, character: 25 }, - end: { line: 1, character: 49 } + end: { line: 1, character: 49 }, }, code: 6133, - message: 'unused arg' + message: 'unused arg', }], - only: [CodeActionKind.SourceOrganizeImportsTs.value] - } + only: [CodeActionKind.SourceOrganizeImportsTs.value], + }, }))!; assert.deepEqual(result, []); @@ -1218,10 +1218,10 @@ describe('code actions', () => { uri: uri('bar.ts'), languageId: 'typescript', version: 1, - text: 'existsSync(\'t\');' + text: 'existsSync(\'t\');', }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); await server.requestDiagnostics(); await new Promise(resolve => setTimeout(resolve, 200)); @@ -1229,12 +1229,12 @@ describe('code actions', () => { textDocument: doc, range: { start: { line: 1, character: 29 }, - end: { line: 1, character: 53 } + end: { line: 1, character: 53 }, }, context: { diagnostics: [], - only: [CodeActionKind.SourceAddMissingImportsTs.value] - } + only: [CodeActionKind.SourceAddMissingImportsTs.value], + }, }))!; assert.deepEqual(result, [ @@ -1251,23 +1251,23 @@ describe('code actions', () => { range: { end: { character: 0, - line: 0 + line: 0, }, start: { character: 0, - line: 0 - } - } - } + line: 0, + }, + }, + }, ], textDocument: { uri: uri('bar.ts'), - version: 1 - } - } - ] - } - } + version: 1, + }, + }, + ], + }, + }, ]); }); @@ -1279,10 +1279,10 @@ describe('code actions', () => { text: `function foo() { return setTimeout(() => {}) -}` +}`, }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); await server.requestDiagnostics(); await new Promise(resolve => setTimeout(resolve, 200)); @@ -1290,12 +1290,12 @@ describe('code actions', () => { textDocument: doc, range: { start: { line: 0, character: 0 }, - end: { line: 4, character: 0 } + end: { line: 4, character: 0 }, }, context: { diagnostics: [], - only: [CodeActionKind.SourceFixAllTs.value] - } + only: [CodeActionKind.SourceFixAllTs.value], + }, }))!; assert.deepEqual(result, [ @@ -1311,23 +1311,23 @@ describe('code actions', () => { range: { end: { character: 0, - line: 3 + line: 3, }, start: { character: 0, - line: 2 - } - } - } + line: 2, + }, + }, + }, ], textDocument: { uri: uri('bar.ts'), - version: 1 - } - } - ] - } - } + version: 1, + }, + }, + ], + }, + }, ]); }); @@ -1338,28 +1338,28 @@ describe('code actions', () => { version: 1, text: `import { existsSync } from 'fs'; import { accessSync } from 'fs'; -existsSync('t');` +existsSync('t');`, }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); const result = (await server.codeAction({ textDocument: doc, range: { start: { line: 0, character: 0 }, - end: { line: 3, character: 0 } + end: { line: 3, character: 0 }, }, context: { diagnostics: [{ range: { start: { line: 1, character: 25 }, - end: { line: 1, character: 49 } + end: { line: 1, character: 49 }, }, code: 6133, - message: 'unused arg' + message: 'unused arg', }], - only: [CodeActionKind.SourceOrganizeImportsTs.value] - } + only: [CodeActionKind.SourceOrganizeImportsTs.value], + }, }))!; assert.deepEqual(result, [ @@ -1375,36 +1375,36 @@ existsSync('t');` range: { end: { character: 0, - line: 1 + line: 1, }, start: { character: 0, - line: 0 - } - } + line: 0, + }, + }, }, { newText: '', range: { end: { character: 0, - line: 2 + line: 2, }, start: { character: 0, - line: 1 - } - } - } + line: 1, + }, + }, + }, ], textDocument: { uri: uri('bar.ts'), - version: 1 - } - } - ] - } - } + version: 1, + }, + }, + ], + }, + }, ]); }); @@ -1413,10 +1413,10 @@ existsSync('t');` uri: uri('bar.ts'), languageId: 'typescript', version: 1, - text: 'import { existsSync } from \'fs\';' + text: 'import { existsSync } from \'fs\';', }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); await server.requestDiagnostics(); await new Promise(resolve => setTimeout(resolve, 200)); @@ -1424,12 +1424,12 @@ existsSync('t');` textDocument: doc, range: { start: position(doc, 'existsSync'), - end: positionAfter(doc, 'existsSync') + end: positionAfter(doc, 'existsSync'), }, context: { diagnostics: [], - only: [CodeActionKind.SourceRemoveUnusedTs.value] - } + only: [CodeActionKind.SourceRemoveUnusedTs.value], + }, }))!; assert.deepEqual(result, [ @@ -1445,23 +1445,23 @@ existsSync('t');` range: { end: { character: 32, - line: 0 + line: 0, }, start: { character: 0, - line: 0 - } - } - } + line: 0, + }, + }, + }, ], textDocument: { uri: uri('bar.ts'), - version: 1 - } - } - ] - } - } + version: 1, + }, + }, + ], + }, + }, ]); }); @@ -1476,10 +1476,10 @@ existsSync('t');` return setTimeout(() => {}) } - ` + `, }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); await server.requestDiagnostics(); await new Promise(resolve => setTimeout(resolve, 200)); @@ -1487,12 +1487,12 @@ existsSync('t');` textDocument: doc, range: { start: { line: 0, character: 0 }, - end: lastPosition(doc, '}') + end: lastPosition(doc, '}'), }, context: { diagnostics: [], - only: [CodeActionKind.SourceFixAllTs.value] - } + only: [CodeActionKind.SourceFixAllTs.value], + }, }))!; assert.strictEqual(result.length, 1, JSON.stringify(result, null, 2)); assert.deepEqual(result, [ @@ -1508,23 +1508,23 @@ existsSync('t');` range: { start: { line: 4, - character: 0 + character: 0, }, end: { line: 5, - character: 0 - } - } - } + character: 0, + }, + }, + }, ], textDocument: { uri: uri('bar.ts'), - version: 1 - } - } - ] - } - } + version: 1, + }, + }, + ], + }, + }, ]); }); }); @@ -1536,20 +1536,20 @@ describe('executeCommand', () => { uri: fooUri, languageId: 'typescript', version: 1, - text: 'export function fn(): void {}\nexport function newFn(): void {}' + text: 'export function fn(): void {}\nexport function newFn(): void {}', }; server.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); const codeActions = (await server.codeAction({ textDocument: doc, range: { start: position(doc, 'newFn'), - end: position(doc, 'newFn') + end: position(doc, 'newFn'), }, context: { - diagnostics: [] - } + diagnostics: [], + }, }))!; // Find refactoring code action. const applyRefactoringAction = codeActions.find(action => action.command?.command === Commands.APPLY_REFACTORING); @@ -1557,7 +1557,7 @@ describe('executeCommand', () => { // Execute refactoring action. await server.executeCommand({ command: applyRefactoringAction!.command!.command, - arguments: applyRefactoringAction!.command!.arguments + arguments: applyRefactoringAction!.command!.arguments, }); assert.equal(1, server.workspaceEdits.length); const { changes } = server.workspaceEdits[0].edit; @@ -1576,16 +1576,16 @@ describe('executeCommand', () => { range: { start: { line: 1, - character: 0 + character: 0, }, end: { line: 1, - character: 32 - } + character: 32, + }, }, - newText: '' - } - ] + newText: '', + }, + ], ); assert.deepEqual( change2, @@ -1594,16 +1594,16 @@ describe('executeCommand', () => { range: { start: { line: 0, - character: 0 + character: 0, }, end: { line: 0, - character: 0 - } + character: 0, + }, }, - newText: 'export function newFn(): void { }\n' - } - ] + newText: 'export function newFn(): void { }\n', + }, + ], ); }); @@ -1614,15 +1614,15 @@ describe('executeCommand', () => { uri: indexUri, languageId: 'typescript', version: 1, - text: readContents(filePath('source-definition', 'index.ts')) + text: readContents(filePath('source-definition', 'index.ts')), }; server.didOpenTextDocument({ textDocument: indexDoc }); const result: lsp.Location[] | null = await server.executeCommand({ command: Commands.SOURCE_DEFINITION, arguments: [ indexUri, - position(indexDoc, '/*identifier*/') - ] + position(indexDoc, '/*identifier*/'), + ], }); assert.isNotNull(result); assert.equal(result!.length, 1); @@ -1631,13 +1631,13 @@ describe('executeCommand', () => { range: { start: { line: 0, - character: 13 + character: 13, }, end: { line: 0, - character: 14 - } - } + character: 14, + }, + }, }); }); }); @@ -1652,10 +1652,10 @@ describe('documentHighlight', () => { export declare const Bar: unique symbol; export interface Bar { } - ` + `, }; server.didOpenTextDocument({ - textDocument: barDoc + textDocument: barDoc, }); const fooDoc = { uri: uri('bar.ts'), @@ -1665,15 +1665,15 @@ describe('documentHighlight', () => { import { Bar } from './bar'; export class Foo implements Bar { } - ` + `, }; server.didOpenTextDocument({ - textDocument: fooDoc + textDocument: fooDoc, }); const result = await server.documentHighlight({ textDocument: fooDoc, - position: lastPosition(fooDoc, 'Bar') + position: lastPosition(fooDoc, 'Bar'), }); assert.equal(2, result.length, JSON.stringify(result, undefined, 2)); }); @@ -1713,7 +1713,7 @@ export function two() { export function three() { return "".toString(); } -` +`, }; const fooDoc = { @@ -1731,7 +1731,7 @@ class MyClass { export function factory() { new MyClass().doSomething(); } -` +`, }; function openDocuments() { @@ -1743,7 +1743,7 @@ export function factory() { openDocuments(); const callsResult = await server.calls({ textDocument: fooDoc, - position: position(fooDoc, 'doStuff();') + position: position(fooDoc, 'doStuff();'), }); assert.equal( resultToString(callsResult, lspcalls.CallDirection.Incoming), @@ -1752,7 +1752,7 @@ export function factory() { ↘ doStuff (foo.ts#0) - foo.ts#0 ↘ doSomething (foo.ts#2) - foo.ts#3 ↘ x (foo.ts#4) - foo.ts#4 - `.trim() + `.trim(), ); }); @@ -1760,14 +1760,14 @@ export function factory() { openDocuments(); const callsResult = await server.calls({ textDocument: fooDoc, - position: position(fooDoc, 'doSomething() {') + position: position(fooDoc, 'doSomething() {'), }); assert.equal( resultToString(callsResult, lspcalls.CallDirection.Incoming), ` ↘ doSomething (foo.ts#2) ↘ factory (foo.ts#8) - foo.ts#9 - `.trim() + `.trim(), ); }); @@ -1777,14 +1777,14 @@ export function factory() { const callsResult = await server.calls({ direction, textDocument: fooDoc, - position: position(fooDoc, 'doStuff()') + position: position(fooDoc, 'doStuff()'), }); assert.equal( resultToString(callsResult, direction), ` ↖ doStuff (do.ts#1) ↖ two (do.ts#4) - do.ts#2 - `.trim() + `.trim(), ); }); @@ -1794,7 +1794,7 @@ export function factory() { const callsResult = await server.calls({ direction, textDocument: doDoc, - position: position(doDoc, 'function two()') + position: position(doDoc, 'function two()'), }); assert.equal( resultToString(callsResult, direction), @@ -1802,7 +1802,7 @@ export function factory() { ↖ two (do.ts#4) ↖ three (do.ts#9) - do.ts#5 ↖ ttt (do.ts#6) - do.ts#7 - `.trim() + `.trim(), ); }); }); @@ -1813,13 +1813,13 @@ describe('diagnostics (no client support)', () => { before(async () => { const clientCapabilitiesOverride: lsp.ClientCapabilities = { textDocument: { - publishDiagnostics: undefined - } + publishDiagnostics: undefined, + }, }; localServer = await createServer({ rootUri: null, publishDiagnostics: args => diagnostics.set(args.uri, args), - clientCapabilitiesOverride + clientCapabilitiesOverride, }); }); @@ -1844,10 +1844,10 @@ describe('diagnostics (no client support)', () => { export function foo(): void { missing('test') } - ` + `, }; localServer.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); await localServer.requestDiagnostics(); @@ -1865,7 +1865,7 @@ describe('jsx/tsx project', () => { before(async () => { localServer = await createServer({ rootUri: uri('jsx'), - publishDiagnostics: args => diagnostics.set(args.uri, args) + publishDiagnostics: args => diagnostics.set(args.uri, args), }); }); @@ -1886,10 +1886,10 @@ describe('jsx/tsx project', () => { uri: uri('jsx', 'app.tsx'), languageId: 'typescriptreact', version: 1, - text: readContents(filePath('jsx', 'app.tsx')) + text: readContents(filePath('jsx', 'app.tsx')), }; localServer.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); const completion = await localServer.completion({ textDocument: doc, position: position(doc, 'title') }); @@ -1906,10 +1906,10 @@ describe('inlayHints', () => { settings: { typescript: { inlayHints: { - includeInlayFunctionLikeReturnTypeHints: true - } - } - } + includeInlayFunctionLikeReturnTypeHints: true, + }, + }, + }, }); }); @@ -1918,10 +1918,10 @@ describe('inlayHints', () => { settings: { typescript: { inlayHints: { - includeInlayFunctionLikeReturnTypeHints: false - } - } - } + includeInlayFunctionLikeReturnTypeHints: false, + }, + }, + }, }); }); @@ -1934,7 +1934,7 @@ describe('inlayHints', () => { export function foo() { return 3 } - ` + `, }; server.didOpenTextDocument({ textDocument: doc }); const inlayHints = await server.inlayHints({ textDocument: doc, range: lsp.Range.create(0, 0, 4, 0) }); @@ -1944,7 +1944,7 @@ describe('inlayHints', () => { label: ': number', position: { line: 1, character: 29 }, kind: lsp.InlayHintKind.Type, - paddingLeft: true + paddingLeft: true, }); }); @@ -1957,7 +1957,7 @@ describe('inlayHints', () => { export function foo() { return 3 } - ` + `, }; server.didOpenTextDocument({ textDocument: doc }); const { inlayHints } = await server.inlayHintsLegacy({ textDocument: doc }); @@ -1977,15 +1977,15 @@ describe('completions without client snippet support', () => { textDocument: { completion: { completionItem: { - snippetSupport: false - } - } - } + snippetSupport: false, + }, + }, + }, }; localServer = await createServer({ rootUri: null, publishDiagnostics: args => diagnostics.set(args.uri, args), - clientCapabilitiesOverride + clientCapabilitiesOverride, }); }); @@ -2009,7 +2009,7 @@ describe('completions without client snippet support', () => { text: ` import fs from 'fs' fs.readFile - ` + `, }; localServer.didOpenTextDocument({ textDocument: doc }); const proposals = await localServer.completion({ textDocument: doc, position: positionAfter(doc, 'readFile') }); @@ -2029,10 +2029,10 @@ describe('completions without client snippet support', () => { uri: uri('jsx', 'app.tsx'), languageId: 'typescriptreact', version: 1, - text: readContents(filePath('jsx', 'app.tsx')) + text: readContents(filePath('jsx', 'app.tsx')), }; localServer.didOpenTextDocument({ - textDocument: doc + textDocument: doc, }); const completion = await localServer.completion({ textDocument: doc, position: position(doc, 'title') }); @@ -2053,12 +2053,12 @@ describe('completions without client snippet support', () => { const obj: IFoo = { /*a*/ } - ` + `, }; localServer.didOpenTextDocument({ textDocument: doc }); const proposals = await localServer.completion({ textDocument: doc, - position: positionAfter(doc, '/*a*/') + position: positionAfter(doc, '/*a*/'), }); assert.isNotNull(proposals); assert.lengthOf(proposals!.items, 1); @@ -2066,8 +2066,8 @@ describe('completions without client snippet support', () => { proposals!.items[0], { label: 'bar', - kind: 2 - } + kind: 2, + }, ); }); }); diff --git a/src/lsp-server.ts b/src/lsp-server.ts index 2e3cc4d5..70a7f090 100644 --- a/src/lsp-server.ts +++ b/src/lsp-server.ts @@ -165,7 +165,7 @@ export class LspServer { const { disableAutomaticTypingAcquisition, hostInfo, maxTsServerMemory, npmLocation, locale } = userInitializationOptions; const { logVerbosity, plugins }: TypeScriptInitializationOptions = { logVerbosity: userInitializationOptions.logVerbosity || this.options.tsserverLogVerbosity, - plugins: userInitializationOptions.plugins || [] + plugins: userInitializationOptions.plugins || [], }; const logFile = this.getLogFile(logVerbosity); @@ -204,14 +204,14 @@ export class LspServer { } this.configurationManager.mergeTsPreferences({ - useLabelDetailsInCompletionEntries: this.features.completionLabelDetails + useLabelDetailsInCompletionEntries: this.features.completionLabelDetails, }); this.diagnosticQueue = new DiagnosticEventQueue( diagnostics => this.options.lspClient.publishDiagnostics(diagnostics), this.documents, this.features, - this.logger + this.logger, ); this._tspClient = new TspClient({ apiVersion: typescriptVersion.version || API.defaultVersion, @@ -231,7 +231,7 @@ export class LspServer { this.logger.error(`tsserver process has exited (exit code: ${exitCode}, signal: ${signal}). Stopping the server.`); } this.shutdown(); - } + }, }); const started = this.tspClient.start(); @@ -256,9 +256,9 @@ export class LspServer { jsx: tsp.JsxEmit.Preserve, allowJs: true, allowSyntheticDefaultImports: true, - allowNonTsExtensions: true - } - }) + allowNonTsExtensions: true, + }, + }), ]); const logFileUri = logFile && pathToUri(logFile, undefined); @@ -267,14 +267,14 @@ export class LspServer { textDocumentSync: lsp.TextDocumentSyncKind.Incremental, completionProvider: { triggerCharacters: ['.', '"', '\'', '/', '@', '<'], - resolveProvider: true + resolveProvider: true, }, codeActionProvider: clientCapabilities.textDocument?.codeAction?.codeActionLiteralSupport ? { codeActionKinds: [ ...TypeScriptAutoFixProvider.kinds.map(kind => kind.value), CodeActionKind.SourceOrganizeImportsTs.value, CodeActionKind.QuickFix.value, - CodeActionKind.Refactor.value + CodeActionKind.Refactor.value, ] } : true, definitionProvider: true, documentFormattingProvider: true, @@ -288,8 +288,8 @@ export class LspServer { Commands.APPLY_REFACTORING, Commands.ORGANIZE_IMPORTS, Commands.APPLY_RENAME_FILE, - Commands.SOURCE_DEFINITION - ] + Commands.SOURCE_DEFINITION, + ], }, hoverProvider: true, inlayHintProvider: true, @@ -297,7 +297,7 @@ export class LspServer { referencesProvider: true, signatureHelpProvider: { triggerCharacters: ['(', ',', '<'], - retriggerCharacters: [')'] + retriggerCharacters: [')'], }, workspaceSymbolProvider: true, implementationProvider: true, @@ -319,7 +319,7 @@ export class LspServer { 'enumMember', 'property', 'function', - 'member' + 'member', ], // token from: https://github.com/microsoft/TypeScript/blob/main/src/services/classifier2020.ts#L14 tokenModifiers: [ @@ -328,14 +328,14 @@ export class LspServer { 'async', 'readonly', 'defaultLibrary', - 'local' - ] + 'local', + ], }, full: true, - range: true - } + range: true, + }, }, - logFileUri + logFileUri, }; (initializeResult.capabilities as lspcalls.CallsServerCapabilities).callsProvider = true; this.logger.log('onInitialize result', initializeResult); @@ -421,7 +421,7 @@ export class LspServer { file, fileContent: params.textDocument.text, scriptKindName: this.getScriptKindName(params.textDocument.languageId), - projectRootPath: this.workspaceRoot + projectRootPath: this.workspaceRoot, }); this.requestDiagnostics(); } else { @@ -430,9 +430,9 @@ export class LspServer { textDocument: params.textDocument, contentChanges: [ { - text: params.textDocument.text - } - ] + text: params.textDocument.text, + }, + ], }); } } @@ -466,7 +466,7 @@ export class LspServer { // so we don't leave stale ones. this.options.lspClient.publishDiagnostics({ uri: document.uri, - diagnostics: [] + diagnostics: [], }); } @@ -510,7 +510,7 @@ export class LspServer { offset, endLine, endOffset, - insertString: change.text + insertString: change.text, }); document.applyEdit(textDocument.version, change); } @@ -524,21 +524,21 @@ export class LspServer { async definition(params: lsp.DefinitionParams): Promise { return this.getDefinition({ type: this.features.definitionLinkSupport ? CommandTypes.DefinitionAndBoundSpan : CommandTypes.Definition, - params + params, }); } async implementation(params: lsp.TextDocumentPositionParams): Promise { return this.getSymbolLocations({ type: CommandTypes.Implementation, - params + params, }); } async typeDefinition(params: lsp.TextDocumentPositionParams): Promise { return this.getSymbolLocations({ type: CommandTypes.TypeDefinition, - params + params, }); } @@ -569,7 +569,7 @@ export class LspServer { originSelectionRange: span, targetRange, targetUri: target.uri, - targetSelectionRange: target.range + targetSelectionRange: target.range, }; }); } @@ -603,7 +603,7 @@ export class LspServer { } const response = await this.tspClient.request(CommandTypes.NavTree, { - file + file, }); const tree = response.body; if (!tree || !tree.childItems) { @@ -650,7 +650,7 @@ export class LspServer { line: params.position.line + 1, offset: params.position.character + 1, triggerCharacter: getCompletionTriggerCharacter(params.context?.triggerCharacter), - triggerKind: params.context?.triggerKind + triggerKind: params.context?.triggerKind, })); const { body } = result; const completions: lsp.CompletionItem[] = []; @@ -707,7 +707,7 @@ export class LspServer { contents.push(documentation + (tags ? '\n\n' + tags : '')); return { contents, - range + range, }; } protected async getQuickInfo(file: string, position: lsp.Position): Promise { @@ -715,7 +715,7 @@ export class LspServer { return await this.tspClient.request(CommandTypes.Quickinfo, { file, line: position.line + 1, - offset: position.character + 1 + offset: position.character + 1, }); } catch (err) { return undefined; @@ -732,7 +732,7 @@ export class LspServer { const result = await this.tspClient.request(CommandTypes.Rename, { file, line: params.position.line + 1, - offset: params.position.character + 1 + offset: params.position.character + 1, }); if (!result.body || !result.body.info.canRename || result.body.locs.length === 0) { @@ -752,8 +752,8 @@ export class LspServer { newText: `${textSpan.prefixText || ''}${params.newName}${textSpan.suffixText || ''}`, range: { start: Position.fromLocation(textSpan.start), - end: Position.fromLocation(textSpan.end) - } + end: Position.fromLocation(textSpan.end), + }, }); }); }); @@ -771,7 +771,7 @@ export class LspServer { const result = await this.tspClient.request(CommandTypes.References, { file, line: params.position.line + 1, - offset: params.position.character + 1 + offset: params.position.character + 1, }); if (!result.body) { return []; @@ -797,7 +797,7 @@ export class LspServer { offset: 1, endLine: Number.MAX_SAFE_INTEGER, endOffset: Number.MAX_SAFE_INTEGER, - options: formatOptions + options: formatOptions, }); if (response.body) { return response.body.map(e => toTextEdit(e)); @@ -821,7 +821,7 @@ export class LspServer { offset: params.range.start.character + 1, endLine: params.range.end.line + 1, endOffset: params.range.end.character + 1, - options: formatOptions + options: formatOptions, }); if (response.body) { return response.body.map(e => toTextEdit(e)); @@ -849,7 +849,7 @@ export class LspServer { file, line: position.line + 1, offset: position.character + 1, - triggerReason: context ? toTsTriggerReason(context) : undefined + triggerReason: context ? toTsTriggerReason(context) : undefined, }); } catch (err) { return undefined; @@ -879,11 +879,11 @@ export class LspServer { // https://github.com/microsoft/TypeScript/issues/43051 const skipDestructiveCodeActions = params.context.diagnostics.some( // assume no severity is an error - d => (d.severity ?? 0) <= 2 + d => (d.severity ?? 0) <= 2, ); const response = await this.getOrganizeImports({ scope: { type: 'file', args }, - skipDestructiveCodeActions + skipDestructiveCodeActions, }); actions.push(...provideOrganizeImports(response, this.documents)); } @@ -956,9 +956,9 @@ export class LspServer { if (renameLocation) { await this.options.lspClient.rename({ textDocument: { - uri: pathToUri(args.file, this.documents) + uri: pathToUri(args.file, this.documents), }, - position: Position.fromLocation(renameLocation) + position: Position.fromLocation(renameLocation), }); } } else if (arg.command === Commands.ORGANIZE_IMPORTS && arg.arguments) { @@ -968,9 +968,9 @@ export class LspServer { const { body } = await this.tspClient.request(CommandTypes.OrganizeImports, { scope: { type: 'file', - args: { file } + args: { file }, }, - skipDestructiveCodeActions: additionalArguments.skipDestructiveCodeActions + skipDestructiveCodeActions: additionalArguments.skipDestructiveCodeActions, }); await this.applyFileCodeEdits(body); } else if (arg.command === Commands.APPLY_RENAME_FILE && arg.arguments) { @@ -1009,7 +1009,7 @@ export class LspServer { changes[pathToUri(edit.fileName, this.documents)] = edit.textChanges.map(toTextEdit); } const { applied } = await this.options.lspClient.applyWorkspaceEdit({ - edit: { changes } + edit: { changes }, }); return applied; } @@ -1027,7 +1027,7 @@ export class LspServer { try { const { body } = await this.tspClient.request(CommandTypes.GetEditsForFileRename, { oldFilePath, - newFilePath + newFilePath, }); return body; } catch (err) { @@ -1047,7 +1047,7 @@ export class LspServer { file, line: arg.position.line + 1, offset: arg.position.character + 1, - filesToSearch: [file] + filesToSearch: [file], }); } catch (err) { return []; @@ -1074,7 +1074,7 @@ export class LspServer { async workspaceSymbol(params: lsp.WorkspaceSymbolParams): Promise { const result = await this.tspClient.request(CommandTypes.Navto, { file: this.lastFileOrDummy(), - searchValue: params.query + searchValue: params.query, }); if (!result.body) { return []; @@ -1085,11 +1085,11 @@ export class LspServer { uri: pathToUri(item.file, this.documents), range: { start: Position.fromLocation(item.start), - end: Position.fromLocation(item.end) - } + end: Position.fromLocation(item.end), + }, }, kind: toSymbolKind(item.kind), - name: item.name + name: item.name, }; }); } @@ -1138,13 +1138,13 @@ export class LspServer { // workaround for https://github.com/Microsoft/vscode/issues/47240 const endLine = range.end.character > 0 && document.getText(lsp.Range.create( lsp.Position.create(range.end.line, range.end.character - 1), - range.end + range.end, )) === '}' ? Math.max(range.end.line - 1, range.start.line) : range.end.line; return { startLine, endLine, - kind + kind, }; } protected asFoldingRangeKind(span: tsp.OutliningSpan): lsp.FoldingRangeKind | undefined { @@ -1168,7 +1168,7 @@ export class LspServer { this.loadingIndicator.finishedLoadingProject((event as tsp.ProjectLoadingFinishEvent).body.projectName); } else { this.logger.log('Ignored event', { - event: event.event + event: event.event, }); } } @@ -1197,7 +1197,7 @@ export class LspServer { async inlayHintsLegacy(params: lspinlayHints.InlayHintsParams): Promise { this.options.lspClient.logMessage({ message: 'Support for experimental "typescript/inlayHints" request is deprecated. Use spec-compliant "textDocument/inlayHint" instead.', - type: lsp.MessageType.Warning + type: lsp.MessageType.Warning, }); const file = uriToPath(params.textDocument.uri); this.logger.log('inlayHints', params, file); @@ -1214,11 +1214,11 @@ export class LspServer { const start = doc.offsetAt(params.range?.start ?? { line: 0, - character: 0 + character: 0, }); const end = doc.offsetAt(params.range?.end ?? { line: doc.lineCount + 1, - character: 0 + character: 0, }); try { @@ -1227,8 +1227,8 @@ export class LspServer { { file, start: start, - length: end - start - } + length: end - start, + }, ); return { @@ -1238,12 +1238,12 @@ export class LspServer { position: Position.fromLocation(item.position), whitespaceAfter: item.whitespaceAfter, whitespaceBefore: item.whitespaceBefore, - kind: item.kind - })) ?? [] + kind: item.kind, + })) ?? [], }; } catch { return { - inlayHints: [] + inlayHints: [], }; } } @@ -1262,11 +1262,11 @@ export class LspServer { const start = doc.offsetAt({ line: 0, - character: 0 + character: 0, }); const end = doc.offsetAt({ line: doc.lineCount, - character: 0 + character: 0, }); return this.getSemanticTokens(doc, file, start, end); @@ -1298,8 +1298,8 @@ export class LspServer { file, start: startOffset, length: endOffset - startOffset, - format: '2020' - } + format: '2020', + }, ); const spans = result.body?.spans ?? []; diff --git a/src/organize-imports.spec.ts b/src/organize-imports.spec.ts index d632d790..8a3024db 100644 --- a/src/organize-imports.spec.ts +++ b/src/organize-imports.spec.ts @@ -11,9 +11,9 @@ describe('provideOrganizeImports', () => { body: [ { fileName, - textChanges: [] - } - ] + textChanges: [], + }, + ], }; const actual = provideOrganizeImports(response as any as tsp.OrganizeImportsResponse, undefined); const expected = [{ @@ -25,11 +25,11 @@ describe('provideOrganizeImports', () => { edits: [], textDocument: { uri: uri('file'), - version: null - } - } - ] - } + version: null, + }, + }, + ], + }, }]; chai.assert.deepEqual(actual, expected); }); diff --git a/src/organize-imports.ts b/src/organize-imports.ts index bf5cde0e..7ff684c0 100644 --- a/src/organize-imports.ts +++ b/src/organize-imports.ts @@ -20,6 +20,6 @@ export function provideOrganizeImports(response: tsp.OrganizeImportsResponse | u lsp.CodeAction.create( 'Organize imports', { documentChanges: response.body.map(edit => toTextDocumentEdit(edit, documents)) }, - CodeActionKind.SourceOrganizeImportsTs.value + CodeActionKind.SourceOrganizeImportsTs.value, )]; } diff --git a/src/protocol-translation.ts b/src/protocol-translation.ts index c427a9c2..fbb8056d 100644 --- a/src/protocol-translation.ts +++ b/src/protocol-translation.ts @@ -71,8 +71,8 @@ export function toLocation(fileSpan: tsp.FileSpan, documents: LspDocuments | und uri: pathToUri(fileSpan.file, documents), range: { start: Position.fromLocation(fileSpan.start), - end: Position.fromLocation(fileSpan.end) - } + end: Position.fromLocation(fileSpan.end), + }, }; } @@ -99,7 +99,7 @@ const symbolKindsMapping: { [name: string]: lsp.SymbolKind; } = { parameter: lsp.SymbolKind.Variable, property: lsp.SymbolKind.Property, setter: lsp.SymbolKind.Method, - var: lsp.SymbolKind.Variable + var: lsp.SymbolKind.Variable, }; export function toSymbolKind(tspKind: string): lsp.SymbolKind { @@ -119,13 +119,13 @@ export function toDiagnostic(diagnostic: tsp.Diagnostic, documents: LspDocuments const lspDiagnostic: lsp.Diagnostic = { range: { start: Position.fromLocation(diagnostic.start), - end: Position.fromLocation(diagnostic.end) + end: Position.fromLocation(diagnostic.end), }, message: diagnostic.text, severity: toDiagnosticSeverity(diagnostic.category), code: diagnostic.code, source: diagnostic.source || 'typescript', - relatedInformation: asRelatedInformation(diagnostic.relatedInformation, documents) + relatedInformation: asRelatedInformation(diagnostic.relatedInformation, documents), }; if (features.diagnosticsTagSupport) { lspDiagnostic.tags = getDiagnosticTags(diagnostic); @@ -154,7 +154,7 @@ function asRelatedInformation(info: tsp.DiagnosticRelatedInformation[] | undefin if (span) { result.push(lsp.DiagnosticRelatedInformation.create( toLocation(span, documents), - item.message + item.message, )); } } @@ -165,9 +165,9 @@ export function toTextEdit(edit: tsp.CodeEdit): lsp.TextEdit { return { range: { start: Position.fromLocation(edit.start), - end: Position.fromLocation(edit.end) + end: Position.fromLocation(edit.end), }, - newText: edit.newText + newText: edit.newText, }; } @@ -175,9 +175,9 @@ export function toTextDocumentEdit(change: tsp.FileCodeEdits, documents: LspDocu return { textDocument: { uri: pathToUri(change.fileName, documents), - version: currentVersion(change.fileName, documents) + version: currentVersion(change.fileName, documents), }, - edits: change.textChanges.map(c => toTextEdit(c)) + edits: change.textChanges.map(c => toTextEdit(c)), }; } @@ -187,8 +187,8 @@ export function toDocumentHighlight(item: tsp.DocumentHighlightsItem): lsp.Docum kind: toDocumentHighlightKind(i.kind), range: { start: Position.fromLocation(i.start), - end: Position.fromLocation(i.end) - } + end: Position.fromLocation(i.end), + }, }; }); } @@ -226,7 +226,7 @@ export function asDocumentation(data: { } return value.length ? { kind: lsp.MarkupKind.Markdown, - value + value, } : undefined; } diff --git a/src/quickfix.ts b/src/quickfix.ts index 26209109..a5ab42b1 100644 --- a/src/quickfix.ts +++ b/src/quickfix.ts @@ -20,8 +20,8 @@ export function provideQuickFix(response: tsp.GetCodeFixesResponse | undefined, { title: fix.description, command: Commands.APPLY_WORKSPACE_EDIT, - arguments: [{ documentChanges: fix.changes.map(c => toTextDocumentEdit(c, documents)) }] + arguments: [{ documentChanges: fix.changes.map(c => toTextDocumentEdit(c, documents)) }], }, - lsp.CodeActionKind.QuickFix + lsp.CodeActionKind.QuickFix, )); } diff --git a/src/refactor.ts b/src/refactor.ts index 1e8824ca..6512d4a3 100644 --- a/src/refactor.ts +++ b/src/refactor.ts @@ -30,7 +30,7 @@ export function asSelectRefactoring(info: tsp.ApplicableRefactorInfo, args: tsp. return lsp.CodeAction.create( info.description, lsp.Command.create(info.description, Commands.SELECT_REFACTORING, info, args), - lsp.CodeActionKind.Refactor + lsp.CodeActionKind.Refactor, ); } @@ -40,9 +40,9 @@ export function asApplyRefactoring(action: tsp.RefactorActionInfo, info: tsp.App lsp.Command.create(action.description, Commands.APPLY_REFACTORING, { ...args, refactor: info.name, - action: action.name + action: action.name, }), - asKind(info) + asKind(info), ); } diff --git a/src/test-utils.ts b/src/test-utils.ts index cc1cec95..bcf7a103 100644 --- a/src/test-utils.ts +++ b/src/test-utils.ts @@ -27,22 +27,22 @@ const DEFAULT_TEST_CLIENT_CAPABILITIES: lsp.ClientCapabilities = { completion: { completionItem: { snippetSupport: true, - labelDetailsSupport: true - } + labelDetailsSupport: true, + }, }, documentSymbol: { - hierarchicalDocumentSymbolSupport: true + hierarchicalDocumentSymbolSupport: true, }, publishDiagnostics: { tagSupport: { valueSet: [ lsp.DiagnosticTag.Unnecessary, - lsp.DiagnosticTag.Deprecated - ] - } + lsp.DiagnosticTag.Deprecated, + ], + }, }, - moniker: {} - } + moniker: {}, + }, }; const DEFAULT_TEST_CLIENT_INITIALIZATION_OPTIONS: TypeScriptInitializationOptions = { @@ -60,8 +60,8 @@ const DEFAULT_TEST_CLIENT_INITIALIZATION_OPTIONS: TypeScriptInitializationOption includeCompletionsWithInsertText: true, includeCompletionsWithSnippetText: true, jsxAttributeCompletionStyle: 'auto', - providePrefixAndSuffixTextForRename: true - } + providePrefixAndSuffixTextForRename: true, + }, }; export function uri(...components: string[]): string { @@ -82,7 +82,7 @@ export function positionAt(document: lsp.TextDocumentItem, idx: number): lsp.Pos const pos = doc.positionAt(idx); return { line: pos.line, - character: pos.character + character: pos.character, }; } @@ -173,7 +173,7 @@ export async function createServer(options: TestLspServerOptions): Promise { @@ -186,7 +186,7 @@ export async function createServer(options: TestLspServerOptions): Promise { server = new TspClient({ apiVersion: API.defaultVersion, logger: new ConsoleLogger(), - tsserverPath: bundled!.tsServerPath + tsserverPath: bundled!.tsServerPath, }); }); @@ -39,13 +39,13 @@ describe('ts server client', () => { const f = filePath('module2.ts'); server.notify(CommandTypes.Open, { file: f, - fileContent: readContents(f) + fileContent: readContents(f), }); const completions = await server.request(CommandTypes.CompletionInfo, { file: f, line: 1, offset: 0, - prefix: 'im' + prefix: 'im', }); assert.isDefined(completions.body); assert.equal(completions.body!.entries[1].name, 'ImageBitmap'); @@ -55,12 +55,12 @@ describe('ts server client', () => { const f = filePath('module2.ts'); server.notify(CommandTypes.Open, { file: f, - fileContent: readContents(f) + fileContent: readContents(f), }); const references = await server.request(CommandTypes.References, { file: f, line: 8, - offset: 16 + offset: 16, }); assert.isDefined(references.body); assert.equal(references.body!.symbolName, 'doStuff'); @@ -70,20 +70,20 @@ describe('ts server client', () => { const f = filePath('module2.ts'); server.notify(CommandTypes.Open, { file: f, - fileContent: readContents(f) + fileContent: readContents(f), }); await server.request(CommandTypes.Configure, { preferences: { - includeInlayFunctionLikeReturnTypeHints: true - } + includeInlayFunctionLikeReturnTypeHints: true, + }, }); const inlayHints = await server.request( CommandTypes.ProvideInlayHints, { file: f, start: 0, - length: 1000 - } + length: 1000, + }, ); assert.isDefined(inlayHints.body); assert.equal(inlayHints.body![0].text, ': boolean'); @@ -93,13 +93,13 @@ describe('ts server client', () => { const f = filePath('module2.ts'); server.notify(CommandTypes.Open, { file: f, - fileContent: readContents(f) + fileContent: readContents(f), }); const response = await server.request(CommandTypes.DocumentHighlights, { file: f, line: 8, offset: 16, - filesToSearch: [f] + filesToSearch: [f], }); assert.isDefined(response.body); assert.isTrue(response.body!.some(({ file }) => file.endsWith('module2.ts')), JSON.stringify(response.body, undefined, 2)); diff --git a/src/tsp-client.ts b/src/tsp-client.ts index aa426a2a..f1212eef 100644 --- a/src/tsp-client.ts +++ b/src/tsp-client.ts @@ -98,7 +98,7 @@ export class TspClient { npmLocation, locale, globalPlugins, - pluginProbeLocations + pluginProbeLocations, } = this.options; const args: string[] = []; if (logFile) { @@ -130,8 +130,8 @@ export class TspClient { const options = { silent: true, execArgv: [ - ...maxTsServerMemory ? [`--max-old-space-size=${maxTsServerMemory}`] : [] - ] + ...maxTsServerMemory ? [`--max-old-space-size=${maxTsServerMemory}`] : [], + ], }; this.tsserverProc = cp.fork(tsserverPath, args, options); this.tsserverProc.on('exit', (exitCode, signal) => { @@ -175,7 +175,7 @@ export class TspClient { request( command: K, args: TypeScriptRequestTypes[K][0], - token?: CancellationToken + token?: CancellationToken, ): Promise { this.sendMessage(command, false, args); const seq = this.seq; @@ -190,7 +190,7 @@ export class TspClient { fs.writeFile(requestCancellationPipeName, '', err => { if (!err) { request.then(() => - fs.unlink(requestCancellationPipeName, () => { /* no-op */ }) + fs.unlink(requestCancellationPipeName, () => { /* no-op */ }), ); } }); @@ -205,7 +205,7 @@ export class TspClient { const request: tsp.Request = { command, seq: this.seq, - type: 'request' + type: 'request', }; if (args) { request.arguments = args; diff --git a/src/tsp-command-types.ts b/src/tsp-command-types.ts index 2756edec..9e2b1925 100644 --- a/src/tsp-command-types.ts +++ b/src/tsp-command-types.ts @@ -196,6 +196,6 @@ export class KindModifiers { KindModifiers.tsxFile, KindModifiers.jsFile, KindModifiers.jsxFile, - KindModifiers.jsonFile + KindModifiers.jsonFile, ]; } diff --git a/src/utils/api.ts b/src/utils/api.ts index 01bba5ac..c5654494 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -64,7 +64,7 @@ export default class API { /** * Full version string including pre-release tags, e.g. '3.9.0-beta' */ - public readonly fullVersionString: string + public readonly fullVersionString: string, ) { } public eq(other: API): boolean { diff --git a/src/utils/typeConverters.ts b/src/utils/typeConverters.ts index 3af9c0fc..575029bd 100644 --- a/src/utils/typeConverters.ts +++ b/src/utils/typeConverters.ts @@ -13,7 +13,7 @@ export namespace Range { export const toTextSpan = (range: lsp.Range): tsp.TextSpan => ({ start: Position.toLocation(range.start), - end: Position.toLocation(range.end) + end: Position.toLocation(range.end), }); export const fromLocations = (start: tsp.Location, end: tsp.Location): lsp.Range => @@ -26,7 +26,7 @@ export namespace Range { startLine: range.start.line + 1, startOffset: range.start.character + 1, endLine: range.end.line + 1, - endOffset: range.end.character + 1 + endOffset: range.end.character + 1, }); export const toFormattingRequestArgs = (file: string, range: lsp.Range): tsp.FormatRequestArgs => ({ @@ -34,7 +34,7 @@ export namespace Range { line: range.start.line + 1, offset: range.start.character + 1, endLine: range.end.line + 1, - endOffset: range.end.character + 1 + endOffset: range.end.character + 1, }); export function intersection(one: lsp.Range, other: lsp.Range): lsp.Range | undefined { @@ -56,19 +56,19 @@ export namespace Position { // even though position is supposed to be 1-based. return { line: Math.max(tslocation.line - 1, 0), - character: Math.max(tslocation.offset - 1, 0) + character: Math.max(tslocation.offset - 1, 0), }; }; export const toLocation = (position: lsp.Position): tsp.Location => ({ line: position.line + 1, - offset: position.character + 1 + offset: position.character + 1, }); export const toFileLocationRequestArgs = (file: string, position: lsp.Position): tsp.FileLocationRequestArgs => ({ file, line: position.line + 1, - offset: position.character + 1 + offset: position.character + 1, }); export function Min(): undefined; diff --git a/src/utils/types.ts b/src/utils/types.ts index 3d09b99b..d231135f 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -20,7 +20,7 @@ export class CodeActionKind { public static readonly SourceFixAllTs = CodeActionKind.SourceFixAll.append('ts'); constructor( - public readonly value: string + public readonly value: string, ) { } public equals(other: CodeActionKind): boolean { diff --git a/src/utils/versionProvider.ts b/src/utils/versionProvider.ts index 016a7070..40920c0c 100644 --- a/src/utils/versionProvider.ts +++ b/src/utils/versionProvider.ts @@ -24,7 +24,7 @@ export class TypeScriptVersion { public readonly source: TypeScriptVersionSource, public readonly path: string, private readonly _pathLabel?: string, - private readonly logger?: Logger + private readonly logger?: Logger, ) { this._api = null; } @@ -149,7 +149,7 @@ export class TypeScriptVersionProvider { TypeScriptVersionSource.UserSetting, resolvedPath, undefined, - this.logger + this.logger, ); }