diff --git a/package.json b/package.json index e3618d106..8a71f409f 100644 --- a/package.json +++ b/package.json @@ -34,10 +34,9 @@ "commitmsg": "validate-commit-msg" }, "dependencies": { - "@reactivex/rxjs": "^5.3.0", "chai": "^4.0.1", "chai-as-promised": "^7.0.0", - "chalk": "^2.0.0", + "chalk": "^2.2.0", "commander": "^2.9.0", "fast-json-patch": "^2.0.2", "glob": "^7.1.1", @@ -47,6 +46,7 @@ "mz": "^2.6.0", "object-hash": "^1.1.8", "opentracing": "^0.14.0", + "rxjs": "^5.5.0", "semaphore-async-await": "^1.5.1", "string-similarity": "^1.1.0", "typescript": "2.4.2", @@ -56,16 +56,15 @@ }, "devDependencies": { "@sourcegraph/tsconfig": "^1.0.0", - "@sourcegraph/tslint-config": "^2.0.1", + "@sourcegraph/tslint-config": "^6.0.0", "@types/chai": "^4.0.0", "@types/chai-as-promised": "^7.1.0", - "@types/chalk": "^0.4.31", "@types/glob": "^5.0.30", "@types/lodash": "^4.14.76", "@types/mocha": "^2.2.41", "@types/mz": "^0.0.31", "@types/node": "^7.0.32", - "@types/object-hash": "^0.5.29", + "@types/object-hash": "^1.1.0", "@types/rimraf": "^2.0.2", "@types/sinon": "^2.3.5", "@types/temp": "^0.8.29", @@ -77,7 +76,7 @@ "rimraf": "^2.6.1", "semantic-release": "^8.0.0", "sinon": "^4.0.0", - "source-map-support": "^0.4.11", + "source-map-support": "^0.5.0", "temp": "^0.8.3", "tslint": "^5.7.0", "tslint-language-service": "^0.9.6", diff --git a/src/connection.ts b/src/connection.ts index dd5b0093c..7ea482d3e 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -1,8 +1,8 @@ -import { Observable, Subscription, Symbol } from '@reactivex/rxjs' import { EventEmitter } from 'events' import { applyReducer, Operation } from 'fast-json-patch' import { camelCase, omit } from 'lodash' import { FORMAT_TEXT_MAP, SpanContext, Tracer } from 'opentracing' +import { Observable, Subscription, Symbol } from 'rxjs' import { inspect } from 'util' import { ErrorCodes, Message, StreamMessageReader as VSCodeStreamMessageReader, StreamMessageWriter as VSCodeStreamMessageWriter } from 'vscode-jsonrpc' import { isNotificationMessage, isRequestMessage, isResponseMessage, NotificationMessage, RequestMessage, ResponseMessage } from 'vscode-jsonrpc/lib/messages' @@ -209,8 +209,8 @@ export function registerLanguageHandler( id: message.params.id, error: { message: 'Request cancelled', - code: ErrorCodes.RequestCancelled - } + code: ErrorCodes.RequestCancelled, + }, }) return } @@ -230,8 +230,8 @@ export function registerLanguageHandler( id: message.id, error: { code: ErrorCodes.MethodNotFound, - message: `Method ${method} not implemented` - } + message: `Method ${method} not implemented`, + }, }) } else { logger.warn(`Method ${method} not implemented`) @@ -264,8 +264,8 @@ export function registerLanguageHandler( method: '$/partialResult', params: { id: message.id, - patch: [patch] - } as PartialResultParams + patch: [patch], + } as PartialResultParams, }) } }) @@ -287,7 +287,7 @@ export function registerLanguageHandler( messageWriter.write({ jsonrpc: '2.0', id: message.id, - result + result, }) }, err => { // Set error on span @@ -302,8 +302,8 @@ export function registerLanguageHandler( error: { message: err.message + '', code: typeof err.code === 'number' ? err.code : ErrorCodes.UnknownErrorCode, - data: omit(err, ['message', 'code']) - } + data: omit(err, ['message', 'code']), + }, }) }) // Save subscription for $/cancelRequest diff --git a/src/diagnostics.ts b/src/diagnostics.ts index 1b5ca0c69..74f446739 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -10,7 +10,7 @@ export function convertTsDiagnostic(diagnostic: ts.Diagnostic): Diagnostic { if (diagnostic.file && diagnostic.start && diagnostic.length) { range = { start: diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), - end: diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start + diagnostic.length) + end: diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start + diagnostic.length), } } return { @@ -18,7 +18,7 @@ export function convertTsDiagnostic(diagnostic: ts.Diagnostic): Diagnostic { message: text, severity: convertDiagnosticCategory(diagnostic.category), code: diagnostic.code, - source: diagnostic.source || 'ts' + source: diagnostic.source || 'ts', } } diff --git a/src/fs.ts b/src/fs.ts index 6392f0dd9..09554b5ed 100644 --- a/src/fs.ts +++ b/src/fs.ts @@ -1,7 +1,7 @@ -import { Observable } from '@reactivex/rxjs' import { Glob } from 'glob' import * as fs from 'mz/fs' import { Span } from 'opentracing' +import { Observable } from 'rxjs' import Semaphore from 'semaphore-async-await' import { LanguageClient } from './lang-handler' import { InMemoryFileSystem } from './memfs' @@ -75,7 +75,7 @@ export class LocalFileSystem implements FileSystem { cwd, nodir: true, matchBase: true, - follow: true + follow: true, }) globber.on('match', (file: string) => { subscriber.next(normalizeUri(base + file)) @@ -189,9 +189,8 @@ export class FileSystemUpdater { * @param span An OpenTracing span for tracing */ public ensureStructure(childOf = new Span()): Observable { - return traceObservable('Ensure structure', childOf, span => { - return this.structureFetch || this.fetchStructure(span) - }) + return traceObservable('Ensure structure', childOf, span => + this.structureFetch || this.fetchStructure(span)) } /** diff --git a/src/lang-handler.ts b/src/lang-handler.ts index 1dd17823a..6cce09f67 100644 --- a/src/lang-handler.ts +++ b/src/lang-handler.ts @@ -1,5 +1,5 @@ -import { Observable } from '@reactivex/rxjs' import { FORMAT_TEXT_MAP, Span } from 'opentracing' +import { Observable } from 'rxjs' import { inspect } from 'util' import { isResponseMessage, Message, NotificationMessage, RequestMessage, ResponseMessage } from 'vscode-jsonrpc/lib/messages' import { @@ -8,7 +8,7 @@ import { LogMessageParams, PublishDiagnosticsParams, TextDocumentIdentifier, - TextDocumentItem + TextDocumentItem, } from 'vscode-languageserver' import { HasMeta } from './connection' import { MessageEmitter, MessageWriter } from './connection' @@ -16,7 +16,7 @@ import { CacheGetParams, CacheSetParams, TextDocumentContentParams, - WorkspaceFilesParams + WorkspaceFilesParams, } from './request-type' import { traceObservable } from './tracing' diff --git a/src/language-server-stdio.ts b/src/language-server-stdio.ts index 88a6eeee3..66f97e9e6 100644 --- a/src/language-server-stdio.ts +++ b/src/language-server-stdio.ts @@ -26,7 +26,7 @@ const options: TypeScriptServiceOptions & MessageLogOptions & RegisterLanguageHa strict: program.strict, logMessages: program.trace, logger, - tracer + tracer, } const messageEmitter = new MessageEmitter(process.stdin, options) diff --git a/src/language-server.ts b/src/language-server.ts index 06aa6b5a8..1a3ad7721 100644 --- a/src/language-server.ts +++ b/src/language-server.ts @@ -27,7 +27,7 @@ const options: ServeOptions & TypeScriptServiceOptions = { strict: program.strict, logMessages: program.trace, logger: program.logfile ? new FileLogger(program.logfile) : new StdioLogger(), - tracer: program.enableJaeger ? initTracer({ serviceName: 'javascript-typescript-langserver', sampler: { type: 'const', param: 1 } }) : new Tracer() + tracer: program.enableJaeger ? initTracer({ serviceName: 'javascript-typescript-langserver', sampler: { type: 'const', param: 1 } }) : new Tracer(), } serve(options, client => new TypeScriptService(client, options)) diff --git a/src/logging.ts b/src/logging.ts index abe0288a8..b3661c6c6 100644 --- a/src/logging.ts +++ b/src/logging.ts @@ -1,5 +1,5 @@ -import * as chalk from 'chalk' +import chalk from 'chalk' import * as fs from 'fs' import { inspect } from 'util' import { MessageType } from 'vscode-languageserver' diff --git a/src/packages.ts b/src/packages.ts index 1062ca3af..9a603bc7f 100644 --- a/src/packages.ts +++ b/src/packages.ts @@ -1,8 +1,9 @@ -import { Observable, Subscription } from '@reactivex/rxjs' import { EventEmitter } from 'events' import { Span } from 'opentracing' import * as path from 'path' +import { Observable, Subscription } from 'rxjs' +import { SelectorMethodSignature } from 'rxjs/observable/FromEventObservable' import * as url from 'url' import { Disposable } from './disposable' import { FileSystemUpdater } from './fs' @@ -32,6 +33,18 @@ export interface PackageJson { } } +export const DEPENDENCY_KEYS: ReadonlyArray< + 'dependencies' | + 'devDependencies' | + 'peerDependencies' | + 'optionalDependencies' +> = [ + 'dependencies', + 'devDependencies', + 'peerDependencies', + 'optionalDependencies', +] + /** * Matches: * @@ -96,7 +109,7 @@ export class PackageManager extends EventEmitter implements Disposable { let rootPackageJsonLevel = Infinity // Find locations of package.jsons _not_ inside node_modules this.subscriptions.add( - Observable.fromEvent<[string, string]>(this.inMemoryFileSystem, 'add', Array.of) + Observable.fromEvent(this.inMemoryFileSystem, 'add', Array.of as SelectorMethodSignature<[string, string]>) .subscribe(([uri, content]) => { const parts = url.parse(uri) if (!parts.pathname || !parts.pathname.endsWith('/package.json') || parts.pathname.includes('/node_modules/')) { diff --git a/src/project-manager.ts b/src/project-manager.ts index faf0a858b..c6f462827 100644 --- a/src/project-manager.ts +++ b/src/project-manager.ts @@ -1,9 +1,9 @@ -import { Observable, Subscription } from '@reactivex/rxjs' -import { SelectorMethodSignature } from '@reactivex/rxjs/dist/cjs/observable/FromEventObservable' import iterate from 'iterare' import { noop } from 'lodash' import { Span } from 'opentracing' import * as path from 'path' +import { Observable, Subscription } from 'rxjs' +import { SelectorMethodSignature } from 'rxjs/observable/FromEventObservable' import * as ts from 'typescript' import { Disposable } from './disposable' import { FileSystemUpdater } from './fs' @@ -21,7 +21,7 @@ import { observableFromIterable, path2uri, toUnixPath, - uri2path + uri2path, } from './util' const LAST_FORWARD_OR_BACKWARD_SLASH = /[\\\/][^\\\/]*$/ @@ -389,7 +389,7 @@ export class ProjectConfiguration { project: { projectService: { logger: this.logger }}, // TODO: may need more support languageService: this.getService(), languageServiceHost: this.getHost(), - serverHost: {} // TODO: may need an adapter + serverHost: {}, // TODO: may need an adapter } const pluginModule = pluginModuleFactory({ typescript: ts }) @@ -512,7 +512,7 @@ export class ProjectManager implements Disposable { */ private configs = { js: new Map(), - ts: new Map() + ts: new Map(), } /** @@ -606,9 +606,9 @@ export class ProjectManager implements Disposable { compilerOptions: { module: ts.ModuleKind.CommonJS, allowNonTsExtensions: false, - allowJs: configType === 'js' + allowJs: configType === 'js', }, - include: { js: ['**/*.js', '**/*.jsx'], ts: ['**/*.ts', '**/*.tsx'] }[configType] + include: { js: ['**/*.js', '**/*.jsx'], ts: ['**/*.ts', '**/*.tsx'] }[configType], } const config = new ProjectConfiguration( this.inMemoryFs, diff --git a/src/symbols.ts b/src/symbols.ts index 31bb70fbb..7545d0559 100644 --- a/src/symbols.ts +++ b/src/symbols.ts @@ -15,7 +15,7 @@ export function definitionInfoToSymbolDescriptor(info: ts.DefinitionInfo, rootPa name: info.name || '', containerKind: info.containerKind || '', containerName: info.containerName || '', - filePath: info.fileName + filePath: info.fileName, } // If the symbol is an external module representing a file, set name to the file path if (info.kind === ts.ScriptElementKind.moduleElement && info.name && /[\\\/]/.test(info.name)) { @@ -59,9 +59,9 @@ export function navigateToItemToSymbolInformation(item: ts.NavigateToItem, progr uri: locationUri(sourceFile.fileName), range: { start: ts.getLineAndCharacterOfPosition(sourceFile, item.textSpan.start), - end: ts.getLineAndCharacterOfPosition(sourceFile, item.textSpan.start + item.textSpan.length) - } - } + end: ts.getLineAndCharacterOfPosition(sourceFile, item.textSpan.start + item.textSpan.length), + }, + }, } if (item.containerName) { symbolInformation.containerName = item.containerName.replace(rootPath, '') @@ -125,9 +125,9 @@ export function navigationTreeToSymbolInformation(tree: ts.NavigationTree, paren uri: locationUri(sourceFile.fileName), range: { start: ts.getLineAndCharacterOfPosition(sourceFile, span.start), - end: ts.getLineAndCharacterOfPosition(sourceFile, span.start + span.length) - } - } + end: ts.getLineAndCharacterOfPosition(sourceFile, span.start + span.length), + }, + }, } if (parent && navigationTreeIsSymbol(parent) && parent.text) { symbolInformation.containerName = parent.text.replace(rootPath, '') @@ -144,7 +144,7 @@ export function navigationTreeToSymbolDescriptor(tree: ts.NavigationTree, parent name: tree.text ? tree.text.replace(rootPath, '') : '', containerKind: '', containerName: '', - filePath + filePath, } if (parent && navigationTreeIsSymbol(parent)) { symbolDescriptor.containerKind = parent.kind diff --git a/src/test/connection.test.ts b/src/test/connection.test.ts index a50f81384..69e50044f 100644 --- a/src/test/connection.test.ts +++ b/src/test/connection.test.ts @@ -1,9 +1,9 @@ -import { Observable, Subject } from '@reactivex/rxjs' import * as assert from 'assert' import { EventEmitter } from 'events' import { Operation } from 'fast-json-patch' import { Span } from 'opentracing' +import { Observable, Subject } from 'rxjs' import * as sinon from 'sinon' import { PassThrough } from 'stream' import { ErrorCodes } from 'vscode-jsonrpc' @@ -17,7 +17,7 @@ describe('connection', () => { const handler: TypeScriptService = Object.create(TypeScriptService.prototype) const emitter = new EventEmitter() const writer = { - write: sinon.spy() + write: sinon.spy(), } registerLanguageHandler(emitter as MessageEmitter, writer as any as MessageWriter, handler as TypeScriptService) const params = [1, 1] @@ -29,7 +29,7 @@ describe('connection', () => { const handler = { _privateMethod: sinon.spy() } const emitter = new EventEmitter() const writer = { - write: sinon.spy() + write: sinon.spy(), } registerLanguageHandler(emitter as MessageEmitter, writer as any, handler as any) const params = [1, 1] @@ -44,7 +44,7 @@ describe('connection', () => { handler.textDocumentHover.returns(Promise.resolve(2)) const emitter = new EventEmitter() const writer = { - write: sinon.spy() + write: sinon.spy(), } registerLanguageHandler(emitter as MessageEmitter, writer as any, handler as any) emitter.emit('message', { jsonrpc: '2.0', id: 1, method: 'initialize', params: { capabilities: {} } }) @@ -54,11 +54,11 @@ describe('connection', () => { }) it('should ignore exit notifications', async () => { const handler = { - exit: sinon.spy() + exit: sinon.spy(), } const emitter = new EventEmitter() const writer = { - write: sinon.spy() + write: sinon.spy(), } registerLanguageHandler(emitter as MessageEmitter, writer as any, handler as any) emitter.emit('message', { jsonrpc: '2.0', id: 1, method: 'exit' }) @@ -67,11 +67,11 @@ describe('connection', () => { }) it('should ignore responses', async () => { const handler = { - whatever: sinon.spy() + whatever: sinon.spy(), } const emitter = new EventEmitter() const writer = { - write: sinon.spy() + write: sinon.spy(), } registerLanguageHandler(emitter as MessageEmitter, writer as any, handler as any) emitter.emit('message', { jsonrpc: '2.0', id: 1, method: 'whatever', result: 123 }) @@ -79,11 +79,11 @@ describe('connection', () => { }) it('should log invalid messages', async () => { const handler = { - whatever: sinon.spy() + whatever: sinon.spy(), } const emitter = new EventEmitter() const writer = { - write: sinon.spy() + write: sinon.spy(), } const logger = new NoopLogger() as NoopLogger & { error: sinon.SinonStub } sinon.stub(logger, 'error') @@ -99,7 +99,7 @@ describe('connection', () => { )) const emitter = new EventEmitter() const writer = { - write: sinon.spy() + write: sinon.spy(), } registerLanguageHandler(emitter as MessageEmitter, writer as any, handler as TypeScriptService) const params = [1, 1] @@ -112,11 +112,11 @@ describe('connection', () => { const handler: TypeScriptService = Object.create(TypeScriptService.prototype) const hoverStub = sinon.stub(handler, 'textDocumentHover').returns(Observable.throw(Object.assign(new Error('Something happened'), { code: ErrorCodes.serverErrorStart, - whatever: 123 + whatever: 123, }))) const emitter = new EventEmitter() const writer = { - write: sinon.spy() + write: sinon.spy(), } registerLanguageHandler(emitter as MessageEmitter, writer as any, handler as TypeScriptService) const params = [1, 1] @@ -130,8 +130,8 @@ describe('connection', () => { error: { message: 'Something happened', code: ErrorCodes.serverErrorStart, - data: { whatever: 123 } - } + data: { whatever: 123 }, + }, })) }) it('should call a handler on request and send the returned synchronous value', async () => { @@ -139,7 +139,7 @@ describe('connection', () => { const hoverStub = sinon.stub(handler, 'textDocumentHover').returns(Observable.of({ op: 'add', path: '', value: 2 })) const emitter = new EventEmitter() const writer = { - write: sinon.spy() + write: sinon.spy(), } registerLanguageHandler(emitter as MessageEmitter, writer as any, handler as TypeScriptService) emitter.emit('message', { jsonrpc: '2.0', id: 1, method: 'textDocument/hover', params: [1, 2] }) @@ -152,7 +152,7 @@ describe('connection', () => { const hoverStub = sinon.stub(handler, 'textDocumentHover').returns(Observable.of({ op: 'add', path: '', value: 2 })) const emitter = new EventEmitter() const writer = { - write: sinon.spy() + write: sinon.spy(), } registerLanguageHandler(emitter as MessageEmitter, writer as any, handler as TypeScriptService) const params = [1, 1] @@ -167,7 +167,7 @@ describe('connection', () => { const hoverStub = sinon.stub(handler, 'textDocumentHover').returns(new Observable(subscriber => unsubscribeHandler)) const emitter = new EventEmitter() const writer = { - write: sinon.spy() + write: sinon.spy(), } registerLanguageHandler(emitter as MessageEmitter, writer as any, handler as TypeScriptService) const params = [1, 1] @@ -185,7 +185,7 @@ describe('connection', () => { const hoverStub = sinon.stub(handler, 'textDocumentHover').returns(new Observable(subscriber => unsubscribeHandler)) const emitter = new EventEmitter() const writer = { - write: sinon.spy() + write: sinon.spy(), } registerLanguageHandler(emitter as MessageEmitter, writer as any, handler as TypeScriptService) const params = [1, 1] @@ -200,7 +200,7 @@ describe('connection', () => { const hoverStub = sinon.stub(handler, 'textDocumentHover').returns(new Observable(subscriber => unsubscribeHandler)) const emitter = new EventEmitter() const writer = { - write: sinon.spy() + write: sinon.spy(), } registerLanguageHandler(emitter as MessageEmitter, writer as any, handler as TypeScriptService) const params = [1, 1] @@ -213,11 +213,11 @@ describe('connection', () => { it(`should call shutdown on ${event} if the service was initialized`, async () => { const handler = { initialize: sinon.stub().returns(Observable.of({ op: 'add', path: '', value: { capabilities: {} }})), - shutdown: sinon.stub().returns(Observable.of({ op: 'add', path: '', value: null })) + shutdown: sinon.stub().returns(Observable.of({ op: 'add', path: '', value: null })), } const emitter = new EventEmitter() const writer = { - write: sinon.spy() + write: sinon.spy(), } registerLanguageHandler(emitter as MessageEmitter, writer as any, handler as any) emitter.emit('message', { jsonrpc: '2.0', id: 1, method: 'initialize', params: { capabilities: {} } }) @@ -229,11 +229,11 @@ describe('connection', () => { it(`should not call shutdown on ${event} if the service was not initialized`, async () => { const handler = { initialize: sinon.stub().returns(Observable.of({ op: 'add', path: '', value: { capabilities: {} }})), - shutdown: sinon.stub().returns(Observable.of({ op: 'add', path: '', value: null })) + shutdown: sinon.stub().returns(Observable.of({ op: 'add', path: '', value: null })), } const emitter = new EventEmitter() const writer = { - write: sinon.spy() + write: sinon.spy(), } registerLanguageHandler(emitter as MessageEmitter, writer as any, handler as any) emitter.emit(event) @@ -242,11 +242,11 @@ describe('connection', () => { it(`should not call shutdown again on ${event} if shutdown was already called`, async () => { const handler = { initialize: sinon.stub().returns(Observable.of({ op: 'add', path: '', value: { capabilities: {} }})), - shutdown: sinon.stub().returns(Observable.of({ op: 'add', path: '', value: null })) + shutdown: sinon.stub().returns(Observable.of({ op: 'add', path: '', value: null })), } const emitter = new EventEmitter() const writer = { - write: sinon.spy() + write: sinon.spy(), } registerLanguageHandler(emitter as MessageEmitter, writer as any, handler as any) emitter.emit('message', { jsonrpc: '2.0', id: 1, method: 'shutdown', params: {} }) @@ -266,7 +266,7 @@ describe('connection', () => { const emitter = new EventEmitter() const writer = { - write: sinon.spy() + write: sinon.spy(), } registerLanguageHandler(emitter as MessageEmitter, writer as any, handler as any) @@ -278,13 +278,13 @@ describe('connection', () => { method: '$/partialResult', params: { id: 1, - patch: [{ op: 'add', path: '', value: { capabilities: { streaming: true }}}] - } + patch: [{ op: 'add', path: '', value: { capabilities: { streaming: true }}}], + }, }], 'Expected to send partial result for initialize') assert.deepEqual(writer.write.args[1], [{ jsonrpc: '2.0', id: 1, - result: { capabilities: { streaming: true } } + result: { capabilities: { streaming: true } }, }], 'Expected to send final result for initialize') // Send hover @@ -296,7 +296,7 @@ describe('connection', () => { assert.deepEqual(writer.write.args[2], [{ jsonrpc: '2.0', method: '$/partialResult', - params: { id: 2, patch: [{ op: 'add', path: '', value: [] }] } + params: { id: 2, patch: [{ op: 'add', path: '', value: [] }] }, }], 'Expected to send partial result that initializes array') // Simulate streamed value @@ -304,7 +304,7 @@ describe('connection', () => { assert.deepEqual(writer.write.args[3], [{ jsonrpc: '2.0', method: '$/partialResult', - params: { id: 2, patch: [{ op: 'add', path: '/-', value: 123 }] } + params: { id: 2, patch: [{ op: 'add', path: '/-', value: 123 }] }, }], 'Expected to send partial result that adds 123 to array') // Complete Subject to trigger final response @@ -312,7 +312,7 @@ describe('connection', () => { assert.deepEqual(writer.write.args[4], [{ jsonrpc: '2.0', id: 2, - result: [123] + result: [123], }], 'Expected to send final result [123]') }) }) diff --git a/src/test/fs-helpers.ts b/src/test/fs-helpers.ts index d3cad58ac..4323bf656 100644 --- a/src/test/fs-helpers.ts +++ b/src/test/fs-helpers.ts @@ -1,4 +1,4 @@ -import { Observable } from '@reactivex/rxjs' +import { Observable } from 'rxjs' import { FileSystem } from '../fs' import { observableFromIterable } from '../util' diff --git a/src/test/fs.test.ts b/src/test/fs.test.ts index b2ea61c3a..8144ae7d0 100644 --- a/src/test/fs.test.ts +++ b/src/test/fs.test.ts @@ -59,13 +59,13 @@ describe('fs.ts', () => { rootUri + 'tweedledum', rootUri + 'foo/bar.ts', rootUri + '%40types/diff/index.d.ts', - rootUri + 'node_modules/some_package/src/function.ts' + rootUri + 'node_modules/some_package/src/function.ts', ]) }) it('should return all files under specific root', async () => { const files = await fileSystem.getWorkspaceFiles(rootUri + 'foo').toArray().toPromise() assert.sameMembers(files, [ - rootUri + 'foo/bar.ts' + rootUri + 'foo/bar.ts', ]) }) }) diff --git a/src/test/plugins.test.ts b/src/test/plugins.test.ts index 4041ef5b1..4eb21552c 100644 --- a/src/test/plugins.test.ts +++ b/src/test/plugins.test.ts @@ -27,7 +27,7 @@ describe('plugins', () => { const pluginSettings: PluginSettings = { globalPlugins: ['some-plugin'], allowLocalPluginLoads: false, - pluginProbeLocations: [] + pluginProbeLocations: [], } const pluginFactoryFunc = (modules: any) => 5 const fakeRequire = (path: string) => pluginFactoryFunc @@ -48,16 +48,16 @@ describe('plugins', () => { const pluginSettings: PluginSettings = { globalPlugins: [], allowLocalPluginLoads: true, - pluginProbeLocations: [] + pluginProbeLocations: [], } const pluginFactoryFunc = (modules: any) => 5 const fakeRequire = (path: string) => pluginFactoryFunc const loader = new PluginLoader(rootDir, memfs, pluginSettings, undefined, memfs, fakeRequire) const pluginOption: ts.PluginImport = { - name: 'some-plugin' + name: 'some-plugin', } const compilerOptions: ts.CompilerOptions = { - plugins: [pluginOption] + plugins: [pluginOption], } const applyProxy = sinon.spy() loader.loadPlugins(compilerOptions, applyProxy) diff --git a/src/test/project-manager.test.ts b/src/test/project-manager.test.ts index 0c067ce56..d8d47ff2f 100644 --- a/src/test/project-manager.test.ts +++ b/src/test/project-manager.test.ts @@ -20,7 +20,7 @@ describe('ProjectManager', () => { memfs = new InMemoryFileSystem(rootPath) const configFileUri = rootUri + 'foo/tsconfig.json' const localfs = new MapFileSystem(new Map([ - [configFileUri, '{}'] + [configFileUri, '{}'], ])) const updater = new FileSystemUpdater(localfs, memfs) projectManager = new ProjectManager(rootPath, memfs, updater, true) @@ -40,7 +40,7 @@ describe('ProjectManager', () => { [rootUri + 'project/tsconfig.json', '{ "compilerOptions": { "typeRoots": ["../types"]} }'], [rootUri + 'project/node_modules/%40types/mocha/index.d.ts', 'declare var describe { (description: string, spec: () => void): void; }'], [rootUri + 'project/file.ts', 'describe("test", () => console.log(GLOBALCONSTANT));'], - [rootUri + 'types/types.d.ts', 'declare var GLOBALCONSTANT=1;'] + [rootUri + 'types/types.d.ts', 'declare var GLOBALCONSTANT=1;'], ])) const updater = new FileSystemUpdater(localfs, memfs) @@ -80,7 +80,7 @@ describe('ProjectManager', () => { [rootUri + 'package.json', '{"name": "package-name-1"}'], [rootUri + 'subdirectory-with-tsconfig/package.json', '{"name": "package-name-2"}'], [rootUri + 'subdirectory-with-tsconfig/src/tsconfig.json', '{}'], - [rootUri + 'subdirectory-with-tsconfig/src/dummy.ts', ''] + [rootUri + 'subdirectory-with-tsconfig/src/dummy.ts', ''], ])) const updater = new FileSystemUpdater(localfs, memfs) projectManager = new ProjectManager(rootPath, memfs, updater, true) @@ -97,7 +97,7 @@ describe('ProjectManager', () => { [rootUri + 'node_modules/somelib/index.js', '/// \n/// '], [rootUri + 'node_modules/somelib/pathref.d.ts', ''], [rootUri + 'node_modules/%40types/node/index.d.ts', ''], - [rootUri + 'src/dummy.ts', 'import * as somelib from "somelib";'] + [rootUri + 'src/dummy.ts', 'import * as somelib from "somelib";'], ])) const updater = new FileSystemUpdater(localfs, memfs) projectManager = new ProjectManager(rootPath, memfs, updater, true) @@ -115,7 +115,7 @@ describe('ProjectManager', () => { memfs = new InMemoryFileSystem(rootPath) const localfs = new MapFileSystem(new Map([ [rootUri + 'tsconfig.json', '{}'], - [rootUri + 'src/jsconfig.json', '{}'] + [rootUri + 'src/jsconfig.json', '{}'], ])) const updater = new FileSystemUpdater(localfs, memfs) projectManager = new ProjectManager(rootPath, memfs, updater, true) @@ -135,7 +135,7 @@ describe('ProjectManager', () => { memfs = new InMemoryFileSystem(rootPath) const localfs = new MapFileSystem(new Map([ [rootUri + 'tsconfig.json', '{}'], - [rootUri + 'src/jsconfig.json', '{}'] + [rootUri + 'src/jsconfig.json', '{}'], ])) const updater = new FileSystemUpdater(localfs, memfs) projectManager = new ProjectManager(rootPath, memfs, updater, true) @@ -155,7 +155,7 @@ describe('ProjectManager', () => { const localfs = new MapFileSystem(new Map([ [rootUri + 'tsconfig.json', '{}'], [rootUri + 'foo/bar/tsconfig.json', '{}'], - [rootUri + 'foo/baz/tsconfig.json', '{}'] + [rootUri + 'foo/baz/tsconfig.json', '{}'], ])) const updater = new FileSystemUpdater(localfs, memfs) projectManager = new ProjectManager(rootPath, memfs, updater, true) @@ -165,7 +165,7 @@ describe('ProjectManager', () => { const configs = Array.from(projectManager.getChildConfigurations(rootUri + 'foo')).map(config => config.configFilePath) assert.deepEqual(configs, [ uri2path(rootUri + 'foo/bar/tsconfig.json'), - uri2path(rootUri + 'foo/baz/tsconfig.json') + uri2path(rootUri + 'foo/baz/tsconfig.json'), ]) assert.equal(Array.from(projectManager.configurations()).length, 4) }) diff --git a/src/test/tracing.test.ts b/src/test/tracing.test.ts index f4f7f0214..9d0590c61 100644 --- a/src/test/tracing.test.ts +++ b/src/test/tracing.test.ts @@ -1,8 +1,8 @@ -import { Observable } from '@reactivex/rxjs' import * as chai from 'chai' import chaiAsPromised = require('chai-as-promised') import { Span } from 'opentracing' +import { Observable } from 'rxjs' import * as sinon from 'sinon' import { traceObservable, tracePromise, traceSync } from '../tracing' chai.use(chaiAsPromised) diff --git a/src/test/typescript-service-helpers.ts b/src/test/typescript-service-helpers.ts index cd10e6ebe..e0664f331 100644 --- a/src/test/typescript-service-helpers.ts +++ b/src/test/typescript-service-helpers.ts @@ -1,8 +1,8 @@ -import { Observable } from '@reactivex/rxjs' import * as chai from 'chai' import chaiAsPromised = require('chai-as-promised') import { applyReducer, Operation } from 'fast-json-patch' import { IBeforeAndAfterContext, ISuiteCallbackContext, ITestCallbackContext } from 'mocha' +import { Observable } from 'rxjs' import * as sinon from 'sinon' import * as ts from 'typescript' import { CompletionItemKind, CompletionList, DiagnosticSeverity, InsertTextFormat, TextDocumentIdentifier, TextDocumentItem, WorkspaceEdit } from 'vscode-languageserver' @@ -18,7 +18,7 @@ const assert = chai.assert const DEFAULT_CAPABILITIES: ClientCapabilities = { xcontentProvider: true, - xfilesProvider: true + xfilesProvider: true, } export interface TestContext { @@ -53,12 +53,11 @@ export const initializeTypeScriptService = ( uri: params.textDocument.uri, text: files.get(params.textDocument.uri)!, version: 1, - languageId: '' + languageId: '', }) }) - this.client.workspaceXfiles.callsFake((params: WorkspaceFilesParams): Observable => { - return observableFromIterable(files.keys()).map(uri => ({ uri })).toArray() - }) + this.client.workspaceXfiles.callsFake((params: WorkspaceFilesParams): Observable => + observableFromIterable(files.keys()).map(uri => ({ uri })).toArray()) this.client.xcacheGet.callsFake(() => Observable.of(null)) this.client.workspaceApplyEdit.callsFake(() => Observable.of({applied: true})) this.service = createService(this.client) @@ -66,7 +65,7 @@ export const initializeTypeScriptService = ( await this.service.initialize({ processId: process.pid, rootUri, - capabilities: clientCapabilities || DEFAULT_CAPABILITIES + capabilities: clientCapabilities || DEFAULT_CAPABILITIES, }).toPromise() } @@ -90,20 +89,20 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor [rootUri + 'a.ts', 'const abc = 1; console.log(abc);'], [rootUri + 'foo/b.ts', [ '/* This is class Foo */', - 'export class Foo {}' + 'export class Foo {}', ].join('\n')], [rootUri + 'foo/c.ts', 'import {Foo} from "./b";'], [rootUri + 'd.ts', [ 'export interface I {', ' target: string;', - '}' + '}', ].join('\n')], [rootUri + 'e.ts', [ 'import * as d from "./d";', '', 'let i: d.I = { target: "hi" };', - 'let target = i.target;' - ].join('\n')] + 'let target = i.target;', + ].join('\n')], ]))) afterEach(shutdownService) @@ -112,61 +111,61 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor specify('in same file', async function(this: TestContext & ITestCallbackContext): Promise { const result: Location[] = await this.service.textDocumentDefinition({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 0, - character: 29 - } + character: 29, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, [{ uri: rootUri + 'a.ts', range: { start: { line: 0, - character: 6 + character: 6, }, end: { line: 0, - character: 9 - } - } + character: 9, + }, + }, }]) }) specify('on keyword (non-null)', async function(this: TestContext & ITestCallbackContext): Promise { const result: Location[] = await this.service.textDocumentDefinition({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 0, - character: 0 - } + character: 0, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, []) }) specify('in other file', async function(this: TestContext & ITestCallbackContext): Promise { const result: Location[] = await this.service.textDocumentDefinition({ textDocument: { - uri: rootUri + 'foo/c.ts' + uri: rootUri + 'foo/c.ts', }, position: { line: 0, - character: 9 - } + character: 9, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, [{ uri: rootUri + 'foo/b.ts', range: { start: { line: 1, - character: 13 + character: 13, }, end: { line: 1, - character: 16 - } - } + character: 16, + }, + }, }]) }) }) @@ -174,12 +173,12 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor specify('on interface field reference', async function(this: TestContext & ITestCallbackContext): Promise { const result: SymbolLocationInformation[] = await this.service.textDocumentXdefinition({ textDocument: { - uri: rootUri + 'e.ts' + uri: rootUri + 'e.ts', }, position: { line: 3, - character: 15 - } + character: 15, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, [{ location: { @@ -187,32 +186,32 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { start: { line: 1, - character: 2 + character: 2, }, end: { line: 1, - character: 8 - } - } + character: 8, + }, + }, }, symbol: { filePath: 'd.ts', containerName: 'd.I', containerKind: '', kind: 'property', - name: 'target' - } + name: 'target', + }, }]) }) specify('in same file', async function(this: TestContext & ITestCallbackContext): Promise { const result: SymbolLocationInformation[] = await this.service.textDocumentXdefinition({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 0, - character: 29 - } + character: 29, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, [{ location: { @@ -220,21 +219,21 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { start: { line: 0, - character: 6 + character: 6, }, end: { line: 0, - character: 9 - } - } + character: 9, + }, + }, }, symbol: { filePath: 'a.ts', containerName: '"a"', containerKind: 'module', kind: 'const', - name: 'abc' - } + name: 'abc', + }, }]) }) }) @@ -242,78 +241,78 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor specify('in same file', async function(this: TestContext & ITestCallbackContext): Promise { const result: Hover = await this.service.textDocumentHover({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 0, - character: 29 - } + character: 29, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, { range: { start: { line: 0, - character: 27 + character: 27, }, end: { line: 0, - character: 30 - } + character: 30, + }, }, contents: [ { language: 'typescript', value: 'const abc: 1' }, - '**const**' - ] + '**const**', + ], }) }) specify('in other file', async function(this: TestContext & ITestCallbackContext): Promise { const result: Hover = await this.service.textDocumentHover({ textDocument: { - uri: rootUri + 'foo/c.ts' + uri: rootUri + 'foo/c.ts', }, position: { line: 0, - character: 9 - } + character: 9, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, { range: { end: { line: 0, - character: 11 + character: 11, }, start: { line: 0, - character: 8 - } + character: 8, + }, }, contents: [ { language: 'typescript', value: 'import Foo' }, - '**alias**' - ] + '**alias**', + ], }) }) specify('over keyword (non-null)', async function(this: TestContext & ITestCallbackContext): Promise { const result: Hover = await this.service.textDocumentHover({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 0, - character: 0 - } + character: 0, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, { contents: [] }) }) specify('over non-existent file', async function(this: TestContext & ITestCallbackContext): Promise { await Promise.resolve(assert.isRejected(this.service.textDocumentHover({ textDocument: { - uri: rootUri + 'foo/a.ts' + uri: rootUri + 'foo/a.ts', }, position: { line: 0, - character: 0 - } + character: 0, + }, }).toPromise())) }) }) @@ -334,10 +333,10 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor ' "removeComments": false,', ' "preserveConstEnums": true', ' }', - '}' + '}', ].join('\n')], [rootUri + 'src/tsd.d.ts', '/// '], - [rootUri + 'src/dir/index.ts', 'import * as m from "dep";'] + [rootUri + 'src/dir/index.ts', 'import * as m from "dep";'], ]))) afterEach(shutdownService) @@ -346,74 +345,74 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor specify('with tsd.d.ts', async function(this: TestContext & ITestCallbackContext): Promise { const result: Location[] = await this.service.textDocumentDefinition({ textDocument: { - uri: rootUri + 'src/dir/index.ts' + uri: rootUri + 'src/dir/index.ts', }, position: { line: 0, - character: 20 - } + character: 20, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, [{ uri: rootUri + 'typings/dep.d.ts', range: { start: { line: 0, - character: 15 + character: 15, }, end: { line: 0, - character: 20 - } - } + character: 20, + }, + }, }]) }) describe('on file in project root', function(this: TestContext & ISuiteCallbackContext): void { specify('on import alias', async function(this: TestContext & ITestCallbackContext): Promise { const result: Location[] = await this.service.textDocumentDefinition({ textDocument: { - uri: rootUri + 'src/a.ts' + uri: rootUri + 'src/a.ts', }, position: { line: 0, - character: 12 - } + character: 12, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, [{ uri: rootUri + 'typings/dep.d.ts', range: { start: { line: 0, - character: 15 + character: 15, }, end: { line: 0, - character: 20 - } - } + character: 20, + }, + }, }]) }) specify('on module name', async function(this: TestContext & ITestCallbackContext): Promise { const result: Location[] = await this.service.textDocumentDefinition({ textDocument: { - uri: rootUri + 'src/a.ts' + uri: rootUri + 'src/a.ts', }, position: { line: 0, - character: 20 - } + character: 20, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, [{ uri: rootUri + 'typings/dep.d.ts', range: { start: { line: 0, - character: 15 + character: 15, }, end: { line: 0, - character: 20 - } - } + character: 20, + }, + }, }]) }) }) @@ -429,82 +428,82 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor homepage: 'https://github.com/DefinitelyTyped/DefinitelyTyped', repository: { type: 'git', - url: 'git+https://github.com/DefinitelyTyped/DefinitelyTyped.git' + url: 'git+https://github.com/DefinitelyTyped/DefinitelyTyped.git', }, license: 'MIT', bugs: { - url: 'https://github.com/DefinitelyTyped/DefinitelyTyped/issues' + url: 'https://github.com/DefinitelyTyped/DefinitelyTyped/issues', }, engines: { - node: '>= 6.9.1' + node: '>= 6.9.1', }, scripts: { 'compile-scripts': 'tsc -p scripts', 'new-package': 'node scripts/new-package.js', 'not-needed': 'node scripts/not-needed.js', 'lint': 'node scripts/lint.js', - 'test': 'node node_modules/types-publisher/bin/tester/test.js --run-from-definitely-typed --nProcesses 1' + 'test': 'node node_modules/types-publisher/bin/tester/test.js --run-from-definitely-typed --nProcesses 1', }, devDependencies: { - 'types-publisher': 'Microsoft/types-publisher#production' - } + 'types-publisher': 'Microsoft/types-publisher#production', + }, }, null, 4)], [rootUri + 'types/resolve/index.d.ts', [ '/// ', '', 'type resolveCallback = (err: Error, resolved?: string) => void;', 'declare function resolve(id: string, cb: resolveCallback): void;', - '' + '', ].join('\n')], [rootUri + 'types/resolve/tsconfig.json', JSON.stringify({ compilerOptions: { module: 'commonjs', lib: [ - 'es6' + 'es6', ], noImplicitAny: true, noImplicitThis: true, strictNullChecks: false, baseUrl: '../', typeRoots: [ - '../' + '../', ], types: [], noEmit: true, - forceConsistentCasingInFileNames: true + forceConsistentCasingInFileNames: true, }, files: [ - 'index.d.ts' - ] + 'index.d.ts', + ], })], [rootUri + 'types/notResolve/index.d.ts', [ '/// ', '', 'type resolveCallback = (err: Error, resolved?: string) => void;', 'declare function resolve(id: string, cb: resolveCallback): void;', - '' + '', ].join('\n')], [rootUri + 'types/notResolve/tsconfig.json', JSON.stringify({ compilerOptions: { module: 'commonjs', lib: [ - 'es6' + 'es6', ], noImplicitAny: true, noImplicitThis: true, strictNullChecks: false, baseUrl: '../', typeRoots: [ - '../' + '../', ], types: [], noEmit: true, - forceConsistentCasingInFileNames: true + forceConsistentCasingInFileNames: true, }, files: [ - 'index.d.ts' - ] - })] + 'index.d.ts', + ], + })], ]))) afterEach(shutdownService) @@ -512,7 +511,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor describe('workspaceSymbol()', function(this: TestContext & ISuiteCallbackContext): void { it('should find a symbol by SymbolDescriptor query with name and package name', async function(this: TestContext & ITestCallbackContext): Promise { const result: SymbolInformation[] = await this.service.workspaceSymbol({ - symbol: { name: 'resolveCallback', package: { name: '@types/resolve' } } + symbol: { name: 'resolveCallback', package: { name: '@types/resolve' } }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, [{ kind: SymbolKind.Variable, @@ -520,16 +519,16 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { end: { character: 63, - line: 2 + line: 2, }, start: { character: 0, - line: 2 - } + line: 2, + }, }, - uri: rootUri + 'types/resolve/index.d.ts' + uri: rootUri + 'types/resolve/index.d.ts', }, - name: 'resolveCallback' + name: 'resolveCallback', }]) }) it('should find a symbol by SymbolDescriptor query with name, containerKind and package name', async function(this: TestContext & ITestCallbackContext): Promise { @@ -538,9 +537,9 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor name: 'resolveCallback', containerKind: 'module', package: { - name: '@types/resolve' - } - } + name: '@types/resolve', + }, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result[0], { kind: SymbolKind.Variable, @@ -548,16 +547,16 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { end: { character: 63, - line: 2 + line: 2, }, start: { character: 0, - line: 2 - } + line: 2, + }, }, - uri: rootUri + 'types/resolve/index.d.ts' + uri: rootUri + 'types/resolve/index.d.ts', }, - name: 'resolveCallback' + name: 'resolveCallback', }) }) }) @@ -571,7 +570,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor [rootUri + 'c.ts', 'import { x } from "dep/dep";'], [rootUri + 'package.json', JSON.stringify({ name: 'mypkg' })], [rootUri + 'node_modules/dep/dep.ts', 'export var x = 1;'], - [rootUri + 'node_modules/dep/package.json', JSON.stringify({ name: 'dep' })] + [rootUri + 'node_modules/dep/package.json', JSON.stringify({ name: 'dep' })], ]))) afterEach(shutdownService) @@ -584,9 +583,9 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor name: 'a', kind: 'class', package: { - name: 'mypkg' - } - } + name: 'mypkg', + }, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result[0], { kind: SymbolKind.Class, @@ -594,21 +593,21 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { end: { character: 33, - line: 0 + line: 0, }, start: { character: 0, - line: 0 - } + line: 0, + }, }, - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, - name: 'a' + name: 'a', }) }) it('should find a symbol by name, kind, package name and ignore package version', async function(this: TestContext & ITestCallbackContext): Promise { const result: SymbolInformation[] = await this.service.workspaceSymbol({ - symbol: { name: 'a', kind: 'class', package: { name: 'mypkg', version: '203940234' } } + symbol: { name: 'a', kind: 'class', package: { name: 'mypkg', version: '203940234' } }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result[0], { kind: SymbolKind.Class, @@ -616,23 +615,23 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { end: { character: 33, - line: 0 + line: 0, }, start: { character: 0, - line: 0 - } + line: 0, + }, }, - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, - name: 'a' + name: 'a', }) }) it('should find a symbol by name', async function(this: TestContext & ITestCallbackContext): Promise { const result: SymbolInformation[] = await this.service.workspaceSymbol({ symbol: { - name: 'a' - } + name: 'a', + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, [{ kind: SymbolKind.Class, @@ -640,16 +639,16 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { end: { character: 33, - line: 0 + line: 0, }, start: { character: 0, - line: 0 - } + line: 0, + }, }, - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, - name: 'a' + name: 'a', }]) }) it('should return no result if the PackageDescriptor does not match', async function(this: TestContext & ITestCallbackContext): Promise { @@ -658,9 +657,9 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor name: 'a', kind: 'class', package: { - name: 'not-mypkg' - } - } + name: 'not-mypkg', + }, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, []) }) @@ -676,16 +675,16 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { end: { character: 33, - line: 0 + line: 0, }, start: { character: 0, - line: 0 - } + line: 0, + }, }, - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, - name: 'a' + name: 'a', }]) }) it('should return all symbols for an empty query excluding dependencies', async function(this: TestContext & ITestCallbackContext): Promise { @@ -701,14 +700,14 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { start: { line: 0, - character: 0 + character: 0, }, end: { line: 0, - character: 33 - } - } - } + character: 33, + }, + }, + }, }, { name: 'foo', @@ -718,15 +717,15 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { start: { line: 0, - character: 10 + character: 10, }, end: { line: 0, - character: 31 - } - } + character: 31, + }, + }, }, - containerName: 'a' + containerName: 'a', }, { name: 'i', @@ -736,15 +735,15 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { start: { line: 0, - character: 24 + character: 24, }, end: { line: 0, - character: 29 - } - } + character: 29, + }, + }, }, - containerName: 'foo' + containerName: 'foo', }, { name: '"c"', @@ -754,14 +753,14 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { start: { line: 0, - character: 0 + character: 0, }, end: { line: 0, - character: 28 - } - } - } + character: 28, + }, + }, + }, }, { name: 'x', @@ -772,14 +771,14 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { start: { line: 0, - character: 9 + character: 9, }, end: { line: 0, - character: 10 - } - } - } + character: 10, + }, + }, + }, }, { name: 'b', @@ -789,14 +788,14 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { start: { line: 0, - character: 0 + character: 0, }, end: { line: 0, - character: 57 - } - } - } + character: 57, + }, + }, + }, }, { name: 'bar', @@ -806,15 +805,15 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { start: { line: 0, - character: 10 + character: 10, }, end: { line: 0, - character: 22 - } - } + character: 22, + }, + }, }, - containerName: 'b' + containerName: 'b', }, { name: 'baz', @@ -824,15 +823,15 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { start: { line: 0, - character: 23 + character: 23, }, end: { line: 0, - character: 56 - } - } + character: 56, + }, + }, }, - containerName: 'b' + containerName: 'b', }, { name: 'qux', @@ -842,15 +841,15 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { start: { line: 0, - character: 59 + character: 59, }, end: { line: 0, - character: 76 - } - } - } - } + character: 76, + }, + }, + }, + }, ]) }) }) @@ -867,21 +866,21 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor containerKind: '', containerName: 'a', name: 'foo', - kind: 'method' + kind: 'method', }, reference: { range: { end: { character: 13, - line: 0 + line: 0, }, start: { character: 9, - line: 0 - } + line: 0, + }, }, - uri: rootUri + 'a.ts' - } + uri: rootUri + 'a.ts', + }, }]) }) it('should return all references to a method with hinted dependee package name', async function(this: TestContext & ITestCallbackContext): Promise { @@ -889,11 +888,11 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor query: { name: 'foo', kind: 'method', - containerName: 'a' + containerName: 'a', }, hints: { - dependeePackageName: 'mypkg' - } + dependeePackageName: 'mypkg', + }, }) .reduce(applyReducer, null as any) .toPromise() @@ -903,21 +902,21 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor containerKind: '', containerName: 'a', name: 'foo', - kind: 'method' + kind: 'method', }, reference: { range: { end: { character: 13, - line: 0 + line: 0, }, start: { character: 9, - line: 0 - } + line: 0, + }, }, - uri: rootUri + 'a.ts' - } + uri: rootUri + 'a.ts', + }, }]) }) it('should return no references to a method if hinted dependee package name was not found', async function(this: TestContext & ITestCallbackContext): Promise { @@ -925,11 +924,11 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor query: { name: 'foo', kind: 'method', - containerName: 'a' + containerName: 'a', }, hints: { - dependeePackageName: 'NOT-mypkg' - } + dependeePackageName: 'NOT-mypkg', + }, }) .reduce(applyReducer, null as any) .toPromise() @@ -944,22 +943,22 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { end: { character: 10, - line: 0 + line: 0, }, start: { character: 8, - line: 0 - } + line: 0, + }, }, - uri: rootUri + 'c.ts' + uri: rootUri + 'c.ts', }, symbol: { filePath: 'dep/dep.ts', containerKind: '', containerName: '"dep/dep"', kind: 'var', - name: 'x' - } + name: 'x', + }, }]) }) it('should return all references to a symbol from a dependency with PackageDescriptor query', async function(this: TestContext & ITestCallbackContext): Promise { @@ -971,14 +970,14 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { end: { character: 10, - line: 0 + line: 0, }, start: { character: 8, - line: 0 - } + line: 0, + }, }, - uri: rootUri + 'c.ts' + uri: rootUri + 'c.ts', }, symbol: { filePath: 'dep/dep.ts', @@ -989,9 +988,9 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor package: { name: 'dep', repoURL: undefined, - version: undefined - } - } + version: undefined, + }, + }, }]) }) it('should return all references to all symbols if empty SymbolDescriptor query is passed', async function(this: TestContext & ITestCallbackContext): Promise { @@ -1005,21 +1004,21 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor containerName: '"a"', containerKind: 'module', kind: 'class', - name: 'a' + name: 'a', }, reference: { range: { end: { character: 7, - line: 0 + line: 0, }, start: { character: 5, - line: 0 - } + line: 0, + }, }, - uri: rootUri + 'a.ts' - } + uri: rootUri + 'a.ts', + }, }, { symbol: { @@ -1027,21 +1026,21 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor containerName: 'a', containerKind: '', name: 'foo', - kind: 'method' + kind: 'method', }, reference: { range: { end: { character: 13, - line: 0 + line: 0, }, start: { character: 9, - line: 0 - } + line: 0, + }, }, - uri: rootUri + 'a.ts' - } + uri: rootUri + 'a.ts', + }, }, { symbol: { @@ -1049,43 +1048,43 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor containerName: '"a"', containerKind: 'module', name: 'i', - kind: 'const' + kind: 'const', }, reference: { range: { end: { character: 25, - line: 0 + line: 0, }, start: { character: 23, - line: 0 - } + line: 0, + }, }, - uri: rootUri + 'a.ts' - } + uri: rootUri + 'a.ts', + }, }, { reference: { range: { end: { character: 10, - line: 0 + line: 0, }, start: { character: 8, - line: 0 - } + line: 0, + }, }, - uri: rootUri + 'c.ts' + uri: rootUri + 'c.ts', }, symbol: { filePath: 'dep/dep.ts', containerKind: '', containerName: '"dep/dep"', kind: 'var', - name: 'x' - } + name: 'x', + }, }, { symbol: { @@ -1093,21 +1092,21 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor containerName: '"foo/b"', containerKind: 'module', name: 'b', - kind: 'class' + kind: 'class', }, reference: { range: { end: { character: 7, - line: 0 + line: 0, }, start: { character: 5, - line: 0 - } + line: 0, + }, }, - uri: rootUri + 'foo/b.ts' - } + uri: rootUri + 'foo/b.ts', + }, }, { symbol: { @@ -1115,21 +1114,21 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor containerName: 'b', containerKind: '', name: 'bar', - kind: 'property' + kind: 'property', }, reference: { range: { end: { character: 13, - line: 0 + line: 0, }, start: { character: 9, - line: 0 - } + line: 0, + }, }, - uri: rootUri + 'foo/b.ts' - } + uri: rootUri + 'foo/b.ts', + }, }, { symbol: { @@ -1137,21 +1136,21 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor containerName: 'b', containerKind: '', name: 'baz', - kind: 'method' + kind: 'method', }, reference: { range: { end: { character: 26, - line: 0 + line: 0, }, start: { character: 22, - line: 0 - } + line: 0, + }, }, - uri: rootUri + 'foo/b.ts' - } + uri: rootUri + 'foo/b.ts', + }, }, { symbol: { @@ -1159,21 +1158,21 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor containerName: 'b', containerKind: '', name: 'bar', - kind: 'property' + kind: 'property', }, reference: { range: { end: { character: 54, - line: 0 + line: 0, }, start: { character: 51, - line: 0 - } + line: 0, + }, }, - uri: rootUri + 'foo/b.ts' - } + uri: rootUri + 'foo/b.ts', + }, }, { symbol: { @@ -1181,22 +1180,22 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor containerName: '"foo/b"', containerKind: 'module', name: 'qux', - kind: 'function' + kind: 'function', }, reference: { range: { end: { character: 71, - line: 0 + line: 0, }, start: { character: 67, - line: 0 - } + line: 0, + }, }, - uri: rootUri + 'foo/b.ts' - } - } + uri: rootUri + 'foo/b.ts', + }, + }, ]) }) }) @@ -1210,7 +1209,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor version: '4.0.2', dependencies: { 'babel-code-frame': '^6.16.0', - 'findup-sync': '~0.3.0' + 'findup-sync': '~0.3.0', }, devDependencies: { '@types/babel-code-frame': '^6.16.0', @@ -1218,27 +1217,27 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor 'chai': '^3.0.0', 'tslint': 'latest', 'tslint-test-config-non-relative': 'file:test/external/tslint-test-config-non-relative', - 'typescript': '2.0.10' + 'typescript': '2.0.10', }, peerDependencies: { - typescript: '>=2.0.0' - } + typescript: '>=2.0.0', + }, })], [rootUri + 'node_modules/dep/package.json', JSON.stringify({ name: 'foo', dependencies: { - shouldnotinclude: '0.0.0' - } + shouldnotinclude: '0.0.0', + }, })], [rootUri + 'subproject/package.json', JSON.stringify({ name: 'subproject', repository: { - url: 'https://github.com/my/subproject' + url: 'https://github.com/my/subproject', }, dependencies: { - 'subproject-dep': '0.0.0' - } - })] + 'subproject-dep': '0.0.0', + }, + })], ]))) afterEach(shutdownService) @@ -1252,93 +1251,93 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor { attributes: { name: 'babel-code-frame', - version: '^6.16.0' + version: '^6.16.0', }, hints: { - dependeePackageName: 'tslint' - } + dependeePackageName: 'tslint', + }, }, { attributes: { name: 'findup-sync', - version: '~0.3.0' + version: '~0.3.0', }, hints: { - dependeePackageName: 'tslint' - } + dependeePackageName: 'tslint', + }, }, { attributes: { name: '@types/babel-code-frame', - version: '^6.16.0' + version: '^6.16.0', }, hints: { - dependeePackageName: 'tslint' - } + dependeePackageName: 'tslint', + }, }, { attributes: { name: '@types/optimist', - version: '0.0.29' + version: '0.0.29', }, hints: { - dependeePackageName: 'tslint' - } + dependeePackageName: 'tslint', + }, }, { attributes: { name: 'chai', - version: '^3.0.0' + version: '^3.0.0', }, hints: { - dependeePackageName: 'tslint' - } + dependeePackageName: 'tslint', + }, }, { attributes: { name: 'tslint', - version: 'latest' + version: 'latest', }, hints: { - dependeePackageName: 'tslint' - } + dependeePackageName: 'tslint', + }, }, { attributes: { name: 'tslint-test-config-non-relative', - version: 'file:test/external/tslint-test-config-non-relative' + version: 'file:test/external/tslint-test-config-non-relative', }, hints: { - dependeePackageName: 'tslint' - } + dependeePackageName: 'tslint', + }, }, { attributes: { name: 'typescript', - version: '2.0.10' + version: '2.0.10', }, hints: { - dependeePackageName: 'tslint' - } + dependeePackageName: 'tslint', + }, }, { attributes: { name: 'typescript', - version: '>=2.0.0' + version: '>=2.0.0', }, hints: { - dependeePackageName: 'tslint' - } + dependeePackageName: 'tslint', + }, }, { attributes: { name: 'subproject-dep', - version: '0.0.0' + version: '0.0.0', }, hints: { - dependeePackageName: 'subproject' - } - } + dependeePackageName: 'subproject', + }, + }, ]) }) }) @@ -1351,100 +1350,100 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor package: { name: 'tslint', version: '4.0.2', - repoURL: undefined + repoURL: undefined, }, dependencies: [ { attributes: { name: 'babel-code-frame', - version: '^6.16.0' + version: '^6.16.0', }, hints: { - dependeePackageName: 'tslint' - } + dependeePackageName: 'tslint', + }, }, { attributes: { name: 'findup-sync', - version: '~0.3.0' + version: '~0.3.0', }, hints: { - dependeePackageName: 'tslint' - } + dependeePackageName: 'tslint', + }, }, { attributes: { name: '@types/babel-code-frame', - version: '^6.16.0' + version: '^6.16.0', }, hints: { - dependeePackageName: 'tslint' - } + dependeePackageName: 'tslint', + }, }, { attributes: { name: '@types/optimist', - version: '0.0.29' + version: '0.0.29', }, hints: { - dependeePackageName: 'tslint' - } + dependeePackageName: 'tslint', + }, }, { attributes: { name: 'chai', - version: '^3.0.0' + version: '^3.0.0', }, hints: { - dependeePackageName: 'tslint' - } + dependeePackageName: 'tslint', + }, }, { attributes: { name: 'tslint', - version: 'latest' + version: 'latest', }, hints: { - dependeePackageName: 'tslint' - } + dependeePackageName: 'tslint', + }, }, { attributes: { name: 'tslint-test-config-non-relative', - version: 'file:test/external/tslint-test-config-non-relative' + version: 'file:test/external/tslint-test-config-non-relative', }, hints: { - dependeePackageName: 'tslint' - } + dependeePackageName: 'tslint', + }, }, { attributes: { name: 'typescript', - version: '2.0.10' + version: '2.0.10', }, hints: { - dependeePackageName: 'tslint' - } + dependeePackageName: 'tslint', + }, }, { attributes: { name: 'typescript', - version: '>=2.0.0' + version: '>=2.0.0', }, hints: { - dependeePackageName: 'tslint' - } - } - ] + dependeePackageName: 'tslint', + }, + }, + ], }, { package: { name: 'subproject', version: undefined, - repoURL: 'https://github.com/my/subproject' + repoURL: 'https://github.com/my/subproject', }, dependencies: [ - { attributes: { name: 'subproject-dep', version: '0.0.0' }, hints: { dependeePackageName: 'subproject' } } - ] + { attributes: { name: 'subproject-dep', version: '0.0.0' }, hints: { dependeePackageName: 'subproject' } }, + ], }]) }) }) @@ -1452,7 +1451,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor describe('TypeScript library', function(this: TestContext & ISuiteCallbackContext): void { beforeEach(initializeTypeScriptService(createService, rootUri, new Map([ - [rootUri + 'a.ts', 'let parameters = [];'] + [rootUri + 'a.ts', 'let parameters = [];'], ]))) afterEach(shutdownService) @@ -1460,28 +1459,28 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor specify('type of parameters should be any[]', async function(this: TestContext & ITestCallbackContext): Promise { const result: Hover = await this.service.textDocumentHover({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 0, - character: 5 - } + character: 5, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, { range: { end: { character: 14, - line: 0 + line: 0, }, start: { character: 4, - line: 0 - } + line: 0, + }, }, contents: [ { language: 'typescript', value: 'let parameters: any[]' }, - '**let**' - ] + '**let**', + ], }) }) }) @@ -1489,7 +1488,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor describe('Live updates', function(this: TestContext & ISuiteCallbackContext): void { beforeEach(initializeTypeScriptService(createService, rootUri, new Map([ - [rootUri + 'a.ts', 'let parameters = [];'] + [rootUri + 'a.ts', 'let parameters = [];'], ]))) afterEach(shutdownService) @@ -1498,33 +1497,33 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor const hoverParams = { textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 0, - character: 5 - } + character: 5, + }, } const range = { end: { character: 14, - line: 0 + line: 0, }, start: { character: 4, - line: 0 - } + line: 0, + }, } await this.service.textDocumentDidChange({ textDocument: { uri: rootUri + 'a.ts', - version: 1 + version: 1, }, contentChanges: [{ - text: 'let parameters: number[]' - }] + text: 'let parameters: number[]', + }], }) const result: Hover = await this.service.textDocumentHover(hoverParams) @@ -1534,8 +1533,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range, contents: [ { language: 'typescript', value: 'let parameters: number[]' }, - '**let**' - ] + '**let**', + ], }) }) @@ -1543,29 +1542,29 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor const hoverParams = { textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 0, - character: 5 - } + character: 5, + }, } const range = { end: { character: 14, - line: 0 + line: 0, }, start: { character: 4, - line: 0 - } + line: 0, + }, } await this.service.textDocumentDidClose({ textDocument: { - uri: rootUri + 'a.ts' - } + uri: rootUri + 'a.ts', + }, }) const result: Hover = await this.service.textDocumentHover(hoverParams) @@ -1575,8 +1574,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range, contents: [ { language: 'typescript', value: 'let parameters: any[]' }, - '**let**' - ] + '**let**', + ], }) }) @@ -1584,23 +1583,23 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor const hoverParams = { textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 0, - character: 5 - } + character: 5, + }, } const range = { end: { character: 14, - line: 0 + line: 0, }, start: { character: 4, - line: 0 - } + line: 0, + }, } { @@ -1611,8 +1610,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range, contents: [ { language: 'typescript', value: 'let parameters: any[]' }, - '**let**' - ] + '**let**', + ], }) } @@ -1621,8 +1620,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor uri: rootUri + 'a.ts', languageId: 'typescript', version: 1, - text: 'let parameters: string[]' - } + text: 'let parameters: string[]', + }, }) { @@ -1633,19 +1632,19 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range, contents: [ { language: 'typescript', value: 'let parameters: string[]' }, - '**let**' - ] + '**let**', + ], }) } await this.service.textDocumentDidChange({ textDocument: { uri: rootUri + 'a.ts', - version: 2 + version: 2, }, contentChanges: [{ - text: 'let parameters: number[]' - }] + text: 'let parameters: number[]', + }], }) { @@ -1656,15 +1655,15 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range, contents: [ { language: 'typescript', value: 'let parameters: number[]' }, - '**let**' - ] + '**let**', + ], }) } await this.service.textDocumentDidClose({ textDocument: { - uri: rootUri + 'a.ts' - } + uri: rootUri + 'a.ts', + }, }) { @@ -1675,8 +1674,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range, contents: [ { language: 'typescript', value: 'let parameters: any[]' }, - '**let**' - ] + '**let**', + ], }) } }) @@ -1685,7 +1684,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor describe('Diagnostics', function(this: TestContext & ISuiteCallbackContext): void { beforeEach(initializeTypeScriptService(createService, rootUri, new Map([ - [rootUri + 'src/errors.ts', 'const text: string = 33;'] + [rootUri + 'src/errors.ts', 'const text: string = 33;'], ]))) afterEach(shutdownService) @@ -1697,8 +1696,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor uri: rootUri + 'src/errors.ts', languageId: 'typescript', text: 'const text: string = 33;', - version: 1 - } + version: 1, + }, }) sinon.assert.calledOnce(this.client.textDocumentPublishDiagnostics) @@ -1708,9 +1707,9 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { end: { character: 10, line: 0 }, start: { character: 6, line: 0 } }, severity: 1, source: 'ts', - code: 2322 + code: 2322, }], - uri: rootUri + 'src/errors.ts' + uri: rootUri + 'src/errors.ts', }) }) @@ -1721,8 +1720,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor uri: rootUri + 'src/errors.ts', languageId: 'typescript', text: 'const text: string = 33;', - version: 1 - } + version: 1, + }, }) this.client.textDocumentPublishDiagnostics.resetHistory() @@ -1730,11 +1729,11 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor await this.service.textDocumentDidChange({ textDocument: { uri: rootUri + 'src/errors.ts', - version: 2 + version: 2, }, contentChanges: [ - { text: 'const text: boolean = 33;' } - ] + { text: 'const text: boolean = 33;' }, + ], }) sinon.assert.calledOnce(this.client.textDocumentPublishDiagnostics) @@ -1744,9 +1743,9 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { end: { character: 10, line: 0 }, start: { character: 6, line: 0 } }, severity: 1, source: 'ts', - code: 2322 + code: 2322, }], - uri: rootUri + 'src/errors.ts' + uri: rootUri + 'src/errors.ts', }) }) @@ -1757,8 +1756,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor uri: rootUri + 'src/errors.ts', languageId: 'typescript', text: 'const text: string = 33;', - version: 1 - } + version: 1, + }, }) this.client.textDocumentPublishDiagnostics.resetHistory() @@ -1766,17 +1765,17 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor await this.service.textDocumentDidChange({ textDocument: { uri: rootUri + 'src/errors.ts', - version: 2 + version: 2, }, contentChanges: [ - { text: 'const text: number = 33;' } - ] + { text: 'const text: number = 33;' }, + ], }) sinon.assert.calledOnce(this.client.textDocumentPublishDiagnostics) sinon.assert.calledWithExactly(this.client.textDocumentPublishDiagnostics, { diagnostics: [], - uri: rootUri + 'src/errors.ts' + uri: rootUri + 'src/errors.ts', }) }) @@ -1784,14 +1783,14 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor await this.service.textDocumentDidClose({ textDocument: { - uri: rootUri + 'src/errors.ts' - } + uri: rootUri + 'src/errors.ts', + }, }) sinon.assert.calledOnce(this.client.textDocumentPublishDiagnostics) sinon.assert.calledWithExactly(this.client.textDocumentPublishDiagnostics, { diagnostics: [], - uri: rootUri + 'src/errors.ts' + uri: rootUri + 'src/errors.ts', }) }) @@ -1816,9 +1815,9 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor ' function foo() : Bar {', ' return null;', ' }', - '}' + '}', ].join('\n')], - [rootUri + 'missing/b.ts', 'namespace t {\n export interface Bar {\n id?: number;\n }}'] + [rootUri + 'missing/b.ts', 'namespace t {\n export interface Bar {\n id?: number;\n }}'], ]))) afterEach(shutdownService) @@ -1827,12 +1826,12 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should resolve symbol imported with tripe-slash reference', async function(this: TestContext & ITestCallbackContext): Promise { const result: Location[] = await this.service.textDocumentDefinition({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 1, - character: 23 - } + character: 23, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, [{ // Note: technically this list should also @@ -1847,61 +1846,61 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { start: { line: 0, - character: 32 + character: 32, }, end: { line: 0, - character: 35 - } - } + character: 35, + }, + }, }]) }) it('should resolve symbol imported with import statement', async function(this: TestContext & ITestCallbackContext): Promise { const result: Location[] = await this.service.textDocumentDefinition({ textDocument: { - uri: rootUri + 'c.ts' + uri: rootUri + 'c.ts', }, position: { line: 1, - character: 2 - } + character: 2, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, [{ uri: rootUri + 'foo/d.ts', range: { start: { line: 0, - character: 16 + character: 16, }, end: { line: 0, - character: 19 - } - } + character: 19, + }, + }, }]) }) it('should resolve definition with missing reference', async function(this: TestContext & ITestCallbackContext): Promise { const result: Location[] = await this.service.textDocumentDefinition({ textDocument: { - uri: rootUri + 'missing/a.ts' + uri: rootUri + 'missing/a.ts', }, position: { line: 3, - character: 21 - } + character: 21, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, [{ uri: rootUri + 'missing/b.ts', range: { start: { line: 1, - character: 21 + character: 21, }, end: { line: 1, - character: 24 - } - } + character: 24, + }, + }, }]) }) it('should resolve deep definitions', async function(this: TestContext & ITestCallbackContext): Promise { @@ -1910,25 +1909,25 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor // This test will fail once we'll increase (or remove) depth limit const result: Location[] = await this.service.textDocumentDefinition({ textDocument: { - uri: rootUri + 'deeprefs/a.ts' + uri: rootUri + 'deeprefs/a.ts', }, position: { line: 2, - character: 8 - } + character: 8, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, [{ uri: rootUri + 'deeprefs/e.ts', range: { start: { line: 1, - character: 17 + character: 17, }, end: { line: 1, - character: 20 - } - } + character: 20, + }, + }, }]) }) }) @@ -1938,10 +1937,10 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor beforeEach(initializeTypeScriptService(createService, rootUri, new Map([ [rootUri + 'tsconfig.json', JSON.stringify({ compilerOptions: { - lib: ['es2016', 'dom'] - } + lib: ['es2016', 'dom'], + }, })], - [rootUri + 'a.ts', 'function foo(n: Node): {console.log(n.parentNode, NaN})}'] + [rootUri + 'a.ts', 'function foo(n: Node): {console.log(n.parentNode, NaN})}'], ]))) afterEach(shutdownService) @@ -1950,23 +1949,23 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should load local library file', async function(this: TestContext & ITestCallbackContext): Promise { const result: Hover = await this.service.textDocumentHover({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 0, - character: 16 - } + character: 16, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, { range: { end: { character: 20, - line: 0 + line: 0, }, start: { character: 16, - line: 0 - } + line: 0, + }, }, contents: [ { @@ -1994,11 +1993,11 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor ' readonly NOTATION_NODE: number;', ' readonly PROCESSING_INSTRUCTION_NODE: number;', ' readonly TEXT_NODE: number;', - '}' - ].join('\n') + '}', + ].join('\n'), }, - '**var** _(ambient)_' - ] + '**var** _(ambient)_', + ], }) }) }) @@ -2006,58 +2005,58 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should resolve TS libraries to github URL', async function(this: TestContext & ITestCallbackContext): Promise { assert.deepEqual(await this.service.textDocumentDefinition({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 0, - character: 16 - } + character: 16, + }, }).reduce(applyReducer, null as any).toPromise(), [{ uri: 'git://github.com/Microsoft/TypeScript?v' + ts.version + '#lib/lib.dom.d.ts', range: { start: { line: 8259, - character: 10 + character: 10, }, end: { line: 8259, - character: 14 - } - } + character: 14, + }, + }, }, { uri: 'git://github.com/Microsoft/TypeScript?v' + ts.version + '#lib/lib.dom.d.ts', range: { start: { line: 8311, - character: 12 + character: 12, }, end: { line: 8311, - character: 16 - } - } + character: 16, + }, + }, }]) assert.deepEqual(await this.service.textDocumentDefinition({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 0, - character: 50 - } + character: 50, + }, }).reduce(applyReducer, null as any).toPromise(), [{ uri: 'git://github.com/Microsoft/TypeScript?v' + ts.version + '#lib/lib.es5.d.ts', range: { start: { line: 24, - character: 14 + character: 14, }, end: { line: 24, - character: 17 - } - } + character: 17, + }, + }, }]) }) }) @@ -2081,17 +2080,17 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor ' qux: number;', '}', 'const a = new A();', - 'a.baz(32, sd)' + 'a.baz(32, sd)', ].join('\n')], [rootUri + 'uses-import.ts', [ 'import * as i from "./import"', - 'i.d()' + 'i.d()', ].join('\n')], [rootUri + 'also-uses-import.ts', [ 'import {d} from "./import"', - 'd()' + 'd()', ].join('\n')], - [rootUri + 'import.ts', '/** d doc*/ export function d() {}'] + [rootUri + 'import.ts', '/** d doc*/ export function d() {}'], ]))) afterEach(shutdownService) @@ -2099,13 +2098,13 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should provide an empty response when no reference is found', async function(this: TestContext & ITestCallbackContext): Promise { const result = await this.service.textDocumentReferences({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 0, - character: 0 + character: 0, }, - context: { includeDeclaration: false } + context: { includeDeclaration: false }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, []) }) @@ -2113,92 +2112,92 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should include the declaration if requested', async function(this: TestContext & ITestCallbackContext): Promise { const result = await this.service.textDocumentReferences({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 4, - character: 5 + character: 5, }, - context: { includeDeclaration: true } + context: { includeDeclaration: true }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, [{ range: { end: { character: 7, - line: 4 + line: 4, }, start: { character: 4, - line: 4 - } + line: 4, + }, }, - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }]) }) it('should provide a reference within the same file', async function(this: TestContext & ITestCallbackContext): Promise { const result = await this.service.textDocumentReferences({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 10, - character: 5 + character: 5, }, - context: { includeDeclaration: false } + context: { includeDeclaration: false }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, [{ range: { end: { character: 5, - line: 15 + line: 15, }, start: { character: 2, - line: 15 - } + line: 15, + }, }, - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }]) }) it('should provide two references from imports', async function(this: TestContext & ITestCallbackContext): Promise { const result = await this.service.textDocumentReferences({ textDocument: { - uri: rootUri + 'import.ts' + uri: rootUri + 'import.ts', }, position: { line: 0, - character: 28 + character: 28, }, - context: { includeDeclaration: false } + context: { includeDeclaration: false }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, [ { range: { end: { character: 3, - line: 1 + line: 1, }, start: { character: 2, - line: 1 - } + line: 1, + }, }, - uri: rootUri + 'uses-import.ts' + uri: rootUri + 'uses-import.ts', }, { range: { end: { character: 1, - line: 1 + line: 1, }, start: { character: 0, - line: 1 - } + line: 1, + }, }, - uri: rootUri + 'also-uses-import.ts' - } + uri: rootUri + 'also-uses-import.ts', + }, ]) }) }) @@ -2221,24 +2220,24 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor ' qux: number;', '}', 'const a = new A();', - 'a.baz(32, sd)' + 'a.baz(32, sd)', ].join('\n')], [rootUri + 'uses-import.ts', [ 'import * as i from "./import"', - 'i.d()' + 'i.d()', ].join('\n')], [rootUri + 'import.ts', '/** d doc*/ export function d() {}'], [rootUri + 'uses-reference.ts', [ '/// ', - 'let z : foo.' + 'let z : foo.', ].join('\n')], [rootUri + 'reference.ts', [ 'namespace foo {', ' /** bar doc*/', ' export interface bar {}', - '}' + '}', ].join('\n')], - [rootUri + 'empty.ts', ''] + [rootUri + 'empty.ts', ''], ]))) afterEach(shutdownService) @@ -2246,29 +2245,29 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should provide a valid empty response when no signature is found', async function(this: TestContext & ITestCallbackContext): Promise { const result: SignatureHelp = await this.service.textDocumentSignatureHelp({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 0, - character: 0 - } + character: 0, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, { signatures: [], activeSignature: 0, - activeParameter: 0 + activeParameter: 0, }) }) it('should provide signature help with parameters in the same file', async function(this: TestContext & ITestCallbackContext): Promise { const result: SignatureHelp = await this.service.textDocumentSignatureHelp({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 15, - character: 11 - } + character: 11, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, { signatures: [ @@ -2277,27 +2276,27 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor documentation: 'The Baz function', parameters: [{ label: 'num: number', - documentation: 'Number parameter' + documentation: 'Number parameter', }, { label: 'text: string', - documentation: 'Text parameter' - }] - } + documentation: 'Text parameter', + }], + }, ], activeSignature: 0, - activeParameter: 1 + activeParameter: 1, }) }) it('should provide signature help from imported symbols', async function(this: TestContext & ITestCallbackContext): Promise { const result: SignatureHelp = await this.service.textDocumentSignatureHelp({ textDocument: { - uri: rootUri + 'uses-import.ts' + uri: rootUri + 'uses-import.ts', }, position: { line: 1, - character: 4 - } + character: 4, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, { activeSignature: 0, @@ -2305,14 +2304,14 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor signatures: [{ label: 'd(): void', documentation: 'd doc', - parameters: [] - }] + parameters: [], + }], }) }) }) - describe('textDocumentCompletion() with snippets', function(this: TestContext & ISuiteCallbackContext): void{ + describe('textDocumentCompletion() with snippets', function(this: TestContext & ISuiteCallbackContext): void { beforeEach(initializeTypeScriptService(createService, rootUri, new Map([ [rootUri + 'a.ts', [ 'class A {', @@ -2326,17 +2325,17 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor ' qux: number;', '}', 'const a = new A();', - 'a.' - ].join('\n')] + 'a.', + ].join('\n')], ]), { textDocument: { completion: { completionItem: { - snippetSupport: true - } - } + snippetSupport: true, + }, + }, }, - ...DEFAULT_CAPABILITIES + ...DEFAULT_CAPABILITIES, })) afterEach(shutdownService) @@ -2344,12 +2343,12 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should produce completions', async function(this: TestContext & ITestCallbackContext): Promise { const result: CompletionList = await this.service.textDocumentCompletion({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 11, - character: 2 - } + character: 2, + }, }).reduce(applyReducer, null as any).toPromise() assert.equal(result.isIncomplete, false) assert.sameDeepMembers(result.items, [ @@ -2360,8 +2359,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor data: { entryName: 'bar', offset: 222, - uri: rootUri + 'a.ts' - } + uri: rootUri + 'a.ts', + }, }, { label: 'baz', @@ -2370,8 +2369,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor data: { entryName: 'baz', offset: 222, - uri: rootUri + 'a.ts' - } + uri: rootUri + 'a.ts', + }, }, { label: 'foo', @@ -2380,8 +2379,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor data: { entryName: 'foo', offset: 222, - uri: rootUri + 'a.ts' - } + uri: rootUri + 'a.ts', + }, }, { label: 'qux', @@ -2390,21 +2389,21 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor data: { entryName: 'qux', offset: 222, - uri: rootUri + 'a.ts' - } - } + uri: rootUri + 'a.ts', + }, + }, ]) }) it('should resolve completions with snippets', async function(this: TestContext & ITestCallbackContext): Promise { const result: CompletionList = await this.service.textDocumentCompletion({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 11, - character: 2 - } + character: 2, + }, }).reduce(applyReducer, null as any).toPromise() // * A snippet can define tab stops and placeholders with `$1`, `$2` // * and `${3:foo}`. `$0` defines the final tab stop, it defaults to @@ -2430,7 +2429,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor insertTextFormat: InsertTextFormat.Snippet, insertText: 'bar(${1:num})', detail: '(method) A.bar(num: number): number', - data: undefined + data: undefined, }, { label: 'baz', @@ -2440,7 +2439,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor insertTextFormat: InsertTextFormat.Snippet, insertText: 'baz(${1:num})', detail: '(method) A.baz(num: number): string', - data: undefined + data: undefined, }, { label: 'foo', @@ -2450,7 +2449,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor insertTextFormat: InsertTextFormat.Snippet, insertText: 'foo()', detail: '(method) A.foo(): void', - data: undefined + data: undefined, }, { label: 'qux', @@ -2460,8 +2459,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor insertTextFormat: InsertTextFormat.PlainText, insertText: 'qux', detail: '(property) A.qux: number', - data: undefined - } + data: undefined, + }, ]) // tslint:enable:no-invalid-template-strings }) @@ -2481,24 +2480,24 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor ' qux: number;', '}', 'const a = new A();', - 'a.' + 'a.', ].join('\n')], [rootUri + 'uses-import.ts', [ 'import * as i from "./import"', - 'i.' + 'i.', ].join('\n')], [rootUri + 'import.ts', '/** d doc*/ export function d() {}'], [rootUri + 'uses-reference.ts', [ '/// ', - 'let z : foo.' + 'let z : foo.', ].join('\n')], [rootUri + 'reference.ts', [ 'namespace foo {', ' /** bar doc*/', ' export interface bar {}', - '}' + '}', ].join('\n')], - [rootUri + 'empty.ts', ''] + [rootUri + 'empty.ts', ''], ]))) afterEach(shutdownService) @@ -2506,12 +2505,12 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('produces completions in the same file', async function(this: TestContext & ITestCallbackContext): Promise { const result: CompletionList = await this.service.textDocumentCompletion({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 11, - character: 2 - } + character: 2, + }, }).reduce(applyReducer, null as any).toPromise() assert.equal(result.isIncomplete, false) assert.sameDeepMembers(result.items, [ @@ -2519,54 +2518,54 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor data: { entryName: 'bar', offset: 200, - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, label: 'bar', kind: CompletionItemKind.Method, - sortText: '0' + sortText: '0', }, { data: { entryName: 'baz', offset: 200, - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, label: 'baz', kind: CompletionItemKind.Method, - sortText: '0' + sortText: '0', }, { data: { entryName: 'foo', offset: 200, - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, label: 'foo', kind: CompletionItemKind.Method, - sortText: '0' + sortText: '0', }, { data: { entryName: 'qux', offset: 200, - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, label: 'qux', kind: CompletionItemKind.Property, - sortText: '0' - } + sortText: '0', + }, ]) }) it('resolves completions in the same file', async function(this: TestContext & ITestCallbackContext): Promise { const result: CompletionList = await this.service.textDocumentCompletion({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 11, - character: 2 - } + character: 2, + }, }).reduce(applyReducer, null as any).toPromise() assert.equal(result.isIncomplete, false) @@ -2585,7 +2584,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor insertTextFormat: InsertTextFormat.PlainText, sortText: '0', detail: '(method) A.bar(): number', - data: undefined + data: undefined, }, { label: 'baz', @@ -2595,7 +2594,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor insertTextFormat: InsertTextFormat.PlainText, sortText: '0', detail: '(method) A.baz(): string', - data: undefined + data: undefined, }, { label: 'foo', @@ -2605,7 +2604,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor insertTextFormat: InsertTextFormat.PlainText, sortText: '0', detail: '(method) A.foo(): void', - data: undefined + data: undefined, }, { label: 'qux', @@ -2615,8 +2614,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor insertTextFormat: InsertTextFormat.PlainText, sortText: '0', detail: '(property) A.qux: number', - data: undefined - } + data: undefined, + }, ]) }) @@ -2624,12 +2623,12 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('produces completions for imported symbols', async function(this: TestContext & ITestCallbackContext): Promise { const result: CompletionList = await this.service.textDocumentCompletion({ textDocument: { - uri: rootUri + 'uses-import.ts' + uri: rootUri + 'uses-import.ts', }, position: { line: 1, - character: 2 - } + character: 2, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, { isIncomplete: false, @@ -2637,23 +2636,23 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor data: { entryName: 'd', offset: 32, - uri: rootUri + 'uses-import.ts' + uri: rootUri + 'uses-import.ts', }, label: 'd', kind: CompletionItemKind.Function, - sortText: '0' - }] + sortText: '0', + }], }) }) it('produces completions for referenced symbols', async function(this: TestContext & ITestCallbackContext): Promise { const result: CompletionList = await this.service.textDocumentCompletion({ textDocument: { - uri: rootUri + 'uses-reference.ts' + uri: rootUri + 'uses-reference.ts', }, position: { line: 1, - character: 13 - } + character: 13, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, { isIncomplete: false, @@ -2661,24 +2660,24 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor data: { entryName: 'bar', offset: 51, - uri: rootUri + 'uses-reference.ts' + uri: rootUri + 'uses-reference.ts', }, label: 'bar', kind: CompletionItemKind.Interface, - sortText: '0' - }] + sortText: '0', + }], }) }) it('produces completions for empty files', async function(this: TestContext & ITestCallbackContext): Promise { this.timeout(10000) const result: CompletionList = await this.service.textDocumentCompletion({ textDocument: { - uri: rootUri + 'empty.ts' + uri: rootUri + 'empty.ts', }, position: { line: 0, - character: 0 - } + character: 0, + }, }).reduce(applyReducer, null as any).toPromise() assert.notDeepEqual(result.items, []) }) @@ -2699,13 +2698,13 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor ' qux: number;', '}', 'const a = new A();', - 'a.' + 'a.', ].join('\n')], [rootUri + 'uses-import.ts', [ 'import {d} from "./import"', - 'const x = d();' + 'const x = d();', ].join('\n')], - [rootUri + 'import.ts', 'export function d(): number { return 55; }'] + [rootUri + 'import.ts', 'export function d(): number { return 55; }'], ]))) afterEach(shutdownService) @@ -2714,13 +2713,13 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor await Promise.resolve(assert.isRejected( this.service.textDocumentRename({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 0, - character: 1 + character: 1, }, - newName: 'asdf' + newName: 'asdf', }).reduce(applyReducer, null as any).toPromise(), 'This symbol cannot be renamed' )) @@ -2728,13 +2727,13 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should return a correct WorkspaceEdit to rename a class', async function(this: TestContext & ITestCallbackContext): Promise { const result: WorkspaceEdit = await this.service.textDocumentRename({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, position: { line: 0, - character: 6 + character: 6, }, - newName: 'B' + newName: 'B', }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, { changes: { @@ -2743,39 +2742,39 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { end: { character: 7, - line: 0 + line: 0, }, start: { character: 6, - line: 0 - } - } + line: 0, + }, + }, }, { newText: 'B', range: { end: { character: 15, - line: 10 + line: 10, }, start: { character: 14, - line: 10 - } - } - }] - } + line: 10, + }, + }, + }], + }, }) }) it('should return a correct WorkspaceEdit to rename an imported function', async function(this: TestContext & ITestCallbackContext): Promise { const result: WorkspaceEdit = await this.service.textDocumentRename({ textDocument: { - uri: rootUri + 'import.ts' + uri: rootUri + 'import.ts', }, position: { line: 0, - character: 16 + character: 16, }, - newName: 'f' + newName: 'f', }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, { changes: { @@ -2784,40 +2783,40 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { end: { character: 17, - line: 0 + line: 0, }, start: { character: 16, - line: 0 - } - } + line: 0, + }, + }, }], [rootUri + 'uses-import.ts']: [{ newText: 'f', range: { end: { character: 9, - line: 0 + line: 0, }, start: { character: 8, - line: 0 - } - } + line: 0, + }, + }, }, { newText: 'f', range: { end: { character: 11, - line: 1 + line: 1, }, start: { character: 10, - line: 1 - } - } - }] - } + line: 1, + }, + }, + }], + }, }) }) }) @@ -2831,8 +2830,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor '\t\tmissingThis = 33;', '\t}', '}', - 'const a = new A();' - ].join('\n')] + 'const a = new A();', + ].join('\n')], ]))) afterEach(shutdownService) @@ -2849,30 +2848,30 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor '\t\tmissingThis = 33;', '\t}', '}', - 'const a = new A();' + 'const a = new A();', ].join('\n'), - version: 1 - } + version: 1, + }, }) const firstDiagnostic: Diagnostic = { range: { start: { line: 3, character: 4 }, - end: { line: 3, character: 15 } + end: { line: 3, character: 15 }, }, message: 'Cannot find name \'missingThis\'. Did you mean the instance member \'this.missingThis\'?', severity: DiagnosticSeverity.Error, code: 2663, - source: 'ts' + source: 'ts', } const actions: Command[] = await this.service.textDocumentCodeAction({ textDocument: { - uri: rootUri + 'a.ts' + uri: rootUri + 'a.ts', }, range: firstDiagnostic.range, context: { - diagnostics: [firstDiagnostic] - } + diagnostics: [firstDiagnostic], + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(actions, [{ title: 'Add \'this.\' to unresolved variable.', @@ -2881,9 +2880,9 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor fileName: toUnixPath(uri2path(rootUri + 'a.ts')), // path only used by TS service textChanges: [{ span: { start: 49, length: 13 }, - newText: '\t\tthis.missingThis' - }] - }] + newText: '\t\tthis.missingThis', + }], + }], }]) }) @@ -2898,8 +2897,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor ' missingThis = 33;', ' }', '}', - 'const a = new A();' - ].join('\n')] + 'const a = new A();', + ].join('\n')], ]))) afterEach(shutdownService) @@ -2912,9 +2911,9 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor fileName: uri2path(rootUri + 'a.ts'), textChanges: [{ span: { start: 50, length: 15 }, - newText: '\t\tthis.missingThis' - }] - }] + newText: '\t\tthis.missingThis', + }], + }], }).reduce(applyReducer, null as any).toPromise() sinon.assert.calledOnce(this.client.workspaceApplyEdit) @@ -2927,16 +2926,16 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor range: { end: { character: 9, - line: 5 + line: 5, }, start: { character: 0, - line: 3 - } - } - }] - } - } + line: 3, + }, + }, + }], + }, + }, }) }) }) @@ -2949,7 +2948,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor [rootUri + 'special-characters-in-path/%40foo/b.ts', 'export function b() {}'], [rootUri + 'windows/app/master.ts', '/// \nc();'], [rootUri + 'windows/lib/master.ts', '/// '], - [rootUri + 'windows/lib/slave.ts', 'function c() {}'] + [rootUri + 'windows/lib/slave.ts', 'function c() {}'], ]))) afterEach(shutdownService) @@ -2957,79 +2956,79 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should accept files with TypeScript keywords in path', async function(this: TestContext & ITestCallbackContext): Promise { const result: Hover = await this.service.textDocumentHover({ textDocument: { - uri: rootUri + 'keywords-in-path/class/constructor/a.ts' + uri: rootUri + 'keywords-in-path/class/constructor/a.ts', }, position: { line: 0, - character: 16 - } + character: 16, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, { range: { start: { line: 0, - character: 16 + character: 16, }, end: { line: 0, - character: 17 - } + character: 17, + }, }, contents: [ { language: 'typescript', value: 'function a(): void' }, - '**function** _(exported)_' - ] + '**function** _(exported)_', + ], }) }) it('should accept files with special characters in path', async function(this: TestContext & ITestCallbackContext): Promise { const result: Hover = await this.service.textDocumentHover({ textDocument: { - uri: rootUri + 'special-characters-in-path/%40foo/b.ts' + uri: rootUri + 'special-characters-in-path/%40foo/b.ts', }, position: { line: 0, - character: 16 - } + character: 16, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, { range: { start: { line: 0, - character: 16 + character: 16, }, end: { line: 0, - character: 17 - } + character: 17, + }, }, contents: [ { language: 'typescript', value: 'function b(): void' }, - '**function** _(exported)_' - ] + '**function** _(exported)_', + ], }) }) it('should handle Windows-style paths in triple slash references', async function(this: TestContext & ITestCallbackContext): Promise { const result = await this.service.textDocumentDefinition({ textDocument: { - uri: rootUri + 'windows/app/master.ts' + uri: rootUri + 'windows/app/master.ts', }, position: { line: 1, - character: 0 - } + character: 0, + }, }).reduce(applyReducer, null as any).toPromise() assert.deepEqual(result, [{ range: { start: { line: 0, - character: 9 + character: 9, }, end: { line: 0, - character: 10 - } + character: 10, + }, }, - uri: rootUri + 'windows/lib/slave.ts' + uri: rootUri + 'windows/lib/slave.ts', }]) }) }) diff --git a/src/test/util-test.ts b/src/test/util-test.ts index 821c7f127..7f0bc8d09 100644 --- a/src/test/util-test.ts +++ b/src/test/util-test.ts @@ -15,21 +15,21 @@ describe('util', () => { containerName: 'ts', kind: 'interface', name: 'Program', - package: undefined + package: undefined, }, { containerKind: 'module', containerName: 'ts', kind: 'interface', name: 'Program', - package: undefined + package: undefined, }) assert.equal(score, 4) }) it('should return a score of 0.6 if a string property is 60% similar', () => { const score = getMatchingPropertyCount({ - filePath: 'lib/foo.d.ts' + filePath: 'lib/foo.d.ts', }, { - filePath: 'src/foo.ts' + filePath: 'src/foo.ts', }) assert.equal(score, 0.6) }) @@ -39,13 +39,13 @@ describe('util', () => { containerName: 'util', kind: 'var', name: 'colors', - package: undefined + package: undefined, }, { containerKind: '', containerName: '', kind: 'var', name: 'colors', - package: undefined + package: undefined, }) assert.equal(score, 4) }) @@ -54,13 +54,13 @@ describe('util', () => { name: 'a', kind: 'class', package: { name: 'mypkg' }, - containerKind: undefined + containerKind: undefined, }, { kind: 'class', name: 'a', containerKind: '', containerName: '', - package: { name: 'mypkg' } + package: { name: 'mypkg' }, }) assert.equal(score, 3) }) @@ -71,9 +71,9 @@ describe('util', () => { name: 'a', // 1 kind: 'class', // 2 package: { - name: 'mypkg' // 3 + name: 'mypkg', // 3 }, - containerKind: '' // 4 + containerKind: '', // 4 }) assert.equal(count, 4) }) @@ -86,14 +86,14 @@ describe('util', () => { kind: 'interface', name: 'Program', filePath: 'foo/bar.ts', - package: undefined + package: undefined, }, { containerKind: 'module', containerName: 'ts', kind: 'interface', name: 'Program', filePath: 'foo/bar.ts', - package: undefined + package: undefined, }) assert.equal(matches, true) }) @@ -103,14 +103,14 @@ describe('util', () => { kind: 'class', package: { name: 'mypkg' }, filePath: 'foo/bar.ts', - containerKind: undefined + containerKind: undefined, }, { kind: 'class', name: 'a', containerKind: '', containerName: '', filePath: 'foo/bar.ts', - package: { name: 'mypkg' } + package: { name: 'mypkg' }, }) assert.equal(matches, true) }) diff --git a/src/tracing.ts b/src/tracing.ts index 8fc77f24e..2d69773ae 100644 --- a/src/tracing.ts +++ b/src/tracing.ts @@ -1,6 +1,6 @@ -import { Observable } from '@reactivex/rxjs' import { Span } from 'opentracing' +import { Observable } from 'rxjs' /** * Traces a synchronous function by passing it a new child span. diff --git a/src/typescript-service.ts b/src/typescript-service.ts index 2be507a9e..4f99419a4 100644 --- a/src/typescript-service.ts +++ b/src/typescript-service.ts @@ -1,10 +1,10 @@ -import { Observable } from '@reactivex/rxjs' import { Operation } from 'fast-json-patch' import iterate from 'iterare' -import { toPairs } from 'lodash' import { castArray, merge, omit } from 'lodash' +import { toPairs } from 'lodash' import hashObject = require('object-hash') import { Span } from 'opentracing' +import { Observable } from 'rxjs' import * as ts from 'typescript' import * as url from 'url' import { @@ -32,7 +32,7 @@ import { TextDocumentPositionParams, TextDocumentSyncKind, TextEdit, - WorkspaceEdit + WorkspaceEdit, } from 'vscode-languageserver' import { walkMostAST } from './ast' import { convertTsDiagnostic } from './diagnostics' @@ -40,7 +40,7 @@ import { FileSystem, FileSystemUpdater, LocalFileSystem, RemoteFileSystem } from import { LanguageClient } from './lang-handler' import { Logger, LSPLogger } from './logging' import { InMemoryFileSystem, isTypeScriptLibrary } from './memfs' -import { extractDefinitelyTypedPackageName, extractNodeModulesPackageName, PackageJson, PackageManager } from './packages' +import { DEPENDENCY_KEYS, extractDefinitelyTypedPackageName, extractNodeModulesPackageName, PackageJson, PackageManager } from './packages' import { ProjectConfiguration, ProjectManager } from './project-manager' import { CompletionItem, @@ -54,7 +54,7 @@ import { SymbolDescriptor, SymbolLocationInformation, WorkspaceReferenceParams, - WorkspaceSymbolParams + WorkspaceSymbolParams, } from './request-type' import { definitionInfoToSymbolDescriptor, @@ -63,7 +63,7 @@ import { navigationTreeIsSymbol, navigationTreeToSymbolDescriptor, navigationTreeToSymbolInformation, - walkNavigationTree + walkNavigationTree, } from './symbols' import { traceObservable } from './tracing' import { @@ -74,7 +74,7 @@ import { observableFromIterable, path2uri, toUnixPath, - uri2path + uri2path, } from './util' export interface TypeScriptServiceOptions { @@ -111,7 +111,7 @@ const completionKinds: { [name: string]: CompletionItemKind } = { text: CompletionItemKind.Text, unit: CompletionItemKind.Unit, value: CompletionItemKind.Value, - variable: CompletionItemKind.Variable + variable: CompletionItemKind.Variable, } /** @@ -194,11 +194,11 @@ export class TypeScriptService { insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false, insertSpaceBeforeFunctionParenthesis: false, placeOpenBraceOnNewLineForFunctions: false, - placeOpenBraceOnNewLineForControlBlocks: false + placeOpenBraceOnNewLineForControlBlocks: false, }, allowLocalPluginLoads: false, globalPlugins: [], - pluginProbeLocations: [] + pluginProbeLocations: [], } /** @@ -285,7 +285,7 @@ export class TypeScriptService { textDocumentSync: TextDocumentSyncKind.Full, hoverProvider: true, signatureHelpProvider: { - triggerCharacters: ['(', ','] + triggerCharacters: ['(', ','], }, definitionProvider: true, referencesProvider: true, @@ -296,20 +296,20 @@ export class TypeScriptService { xdependenciesProvider: true, completionProvider: { resolveProvider: true, - triggerCharacters: ['.'] + triggerCharacters: ['.'], }, codeActionProvider: true, renameProvider: true, executeCommandProvider: { - commands: [] + commands: [], }, - xpackagesProvider: true - } + xpackagesProvider: true, + }, } return Observable.of({ op: 'add', path: '', - value: result + value: result, } as Operation) } @@ -392,8 +392,8 @@ export class TypeScriptService { uri: locationUri(definition.fileName), range: { start, - end - } + end, + }, } }) }) @@ -460,9 +460,9 @@ export class TypeScriptService { uri: definitionUri, range: { start: ts.getLineAndCharacterOfPosition(sourceFile, definition.textSpan.start), - end: ts.getLineAndCharacterOfPosition(sourceFile, definition.textSpan.start + definition.textSpan.length) - } - } + end: ts.getLineAndCharacterOfPosition(sourceFile, definition.textSpan.start + definition.textSpan.length), + }, + }, } }) }) @@ -486,7 +486,7 @@ export class TypeScriptService { const parts: url.UrlObject = url.parse(uri) const packageJsonUri = url.format({ ...parts, - pathname: parts.pathname!.slice(0, parts.pathname!.lastIndexOf('/node_modules/' + encodedPackageName)) + `/node_modules/${encodedPackageName}/package.json` + pathname: parts.pathname!.slice(0, parts.pathname!.lastIndexOf('/node_modules/' + encodedPackageName)) + `/node_modules/${encodedPackageName}/package.json`, }) // Fetch the package.json of the dependency return this.updater.ensure(packageJsonUri, span) @@ -582,10 +582,13 @@ export class TypeScriptService { || info.kind !== ts.ScriptElementKind.constructorImplementationElement )) // Make proper adjectives - .map(mod => ({ - [ts.ScriptElementKindModifier.ambientModifier]: 'ambient', - [ts.ScriptElementKindModifier.exportedModifier]: 'exported' - })[mod] || mod) + .map(mod => { + switch (mod) { + case ts.ScriptElementKindModifier.ambientModifier: return 'ambient' + case ts.ScriptElementKindModifier.exportedModifier: return 'exported' + default: return mod + } + }) if (modifiers.length > 0) { kind += ' _(' + modifiers.join(', ') + ')_' } @@ -603,8 +606,8 @@ export class TypeScriptService { contents, range: { start, - end - } + end, + }, } }) } @@ -661,8 +664,8 @@ export class TypeScriptService { uri: path2uri(reference.fileName), range: { start, - end - } + end, + }, } }) })) @@ -714,7 +717,7 @@ export class TypeScriptService { throw new Error(`Could not find tsconfig for ${packageRootUri}`) } // Don't match PackageDescriptor on symbols - return this._getSymbolsInConfig(config, omit, Partial>(params.symbol!, 'package'), span) + return this._getSymbolsInConfig(config, omit(params.symbol!, 'package'), span) })) } // Regular workspace symbol search @@ -801,7 +804,7 @@ export class TypeScriptService { * @return Observable of JSON Patches that build a `ReferenceInformation[]` result */ public workspaceXreferences(params: WorkspaceReferenceParams, span = new Span()): Observable { - const queryWithoutPackage = omit, Partial>(params.query, 'package') + const queryWithoutPackage = omit(params.query, 'package') const minScore = Math.min(4.75, getPropertyCount(queryWithoutPackage)) return this.isDefinitelyTyped .mergeMap(isDefinitelyTyped => { @@ -875,9 +878,9 @@ export class TypeScriptService { uri: locationUri(source.fileName), range: { start: ts.getLineAndCharacterOfPosition(source, node.pos), - end: ts.getLineAndCharacterOfPosition(source, node.end) - } - } + end: ts.getLineAndCharacterOfPosition(source, node.end), + }, + }, })) } catch (err) { // Continue with next node on error @@ -918,11 +921,11 @@ export class TypeScriptService { // Get the directory names .map((uri): PackageInformation => ({ package: { - name: '@types/' + decodeURIComponent(uri.substr(typesUri.length).split('/')[0]) + name: '@types/' + decodeURIComponent(uri.substr(typesUri.length).split('/')[0]), // TODO report a version by looking at subfolders like v6 }, // TODO parse /// comments in .d.ts files for collecting dependencies between @types packages - dependencies: [] + dependencies: [], })) } // For other workspaces, search all package.json files @@ -941,27 +944,27 @@ export class TypeScriptService { const packageDescriptor: PackageDescriptor = { name: packageJson.name, version: packageJson.version, - repoURL: typeof packageJson.repository === 'object' && packageJson.repository.url || undefined + repoURL: typeof packageJson.repository === 'object' && packageJson.repository.url || undefined, } // Collect all dependencies for this package.json - return Observable.of('dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies') + return Observable.from(DEPENDENCY_KEYS) .filter(key => !!packageJson[key]) // Get [name, version] pairs - .mergeMap(key => toPairs(packageJson[key]) as [string, string][]) + .mergeMap(key => toPairs(packageJson[key])) // Map to DependencyReferences .map(([name, version]): DependencyReference => ({ attributes: { name, - version + version, }, hints: { - dependeePackageName: packageJson.name - } + dependeePackageName: packageJson.name, + }, })) .toArray() .map((dependencies): PackageInformation => ({ package: packageDescriptor, - dependencies + dependencies, })) }) }) @@ -986,18 +989,18 @@ export class TypeScriptService { .mergeMap(uri => this.packageManager.getPackageJson(uri)) // Map package.json to DependencyReferences .mergeMap(packageJson => - Observable.of('dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies') + Observable.from(DEPENDENCY_KEYS) .filter(key => !!packageJson[key]) // Get [name, version] pairs - .mergeMap(key => toPairs(packageJson[key]) as [string, string][]) + .mergeMap(key => toPairs(packageJson[key])) .map(([name, version]): DependencyReference => ({ attributes: { name, - version + version, }, hints: { - dependeePackageName: packageJson.name - } + dependeePackageName: packageJson.name, + }, })) ) .map((dependency): Operation => ({ op: 'add', path: '/-', value: dependency })) @@ -1060,7 +1063,7 @@ export class TypeScriptService { item.data = { uri, offset, - entryName: entry.name + entryName: entry.name, } return { op: 'add', path: '/items/-', value: item } as Operation @@ -1148,19 +1151,19 @@ export class TypeScriptService { const suffix = ts.displayPartsToString(item.suffixDisplayParts) const parameters = item.parameters.map((p): ParameterInformation => ({ label: ts.displayPartsToString(p.displayParts), - documentation: ts.displayPartsToString(p.documentation) + documentation: ts.displayPartsToString(p.documentation), })) return { label: prefix + params + suffix, documentation: ts.displayPartsToString(item.documentation), - parameters + parameters, } }) return { signatures: signatureInformations, activeSignature: signatures.selectedItemIndex, - activeParameter: signatures.argumentIndex + activeParameter: signatures.argumentIndex, } }) .map(signatureHelp => ({ op: 'add', path: '', value: signatureHelp }) as Operation) @@ -1206,8 +1209,8 @@ export class TypeScriptService { value: { title: action.description, command: 'codeFix', - arguments: action.changes - } as Command + arguments: action.changes, + } as Command, })) .startWith({ op: 'add', path: '', value: [] } as Operation) } @@ -1242,7 +1245,13 @@ export class TypeScriptService { return this.projectManager.ensureOwnFiles(span) .concat(Observable.defer(() => { - const configuration = this.projectManager.getConfiguration(fileTextChanges[0].fileName) + // Configuration lookup uses Windows paths, FileTextChanges uses unix paths. Convert to backslashes. + const unixFilePath = fileTextChanges[0].fileName + const firstChangedFile = /^[a-z]:\//i.test(unixFilePath) ? + unixFilePath.replace(/\//g, '\\') : + unixFilePath + + const configuration = this.projectManager.getConfiguration(firstChangedFile) configuration.ensureBasicFiles(span) const changes: {[uri: string]: TextEdit[]} = {} @@ -1255,9 +1264,9 @@ export class TypeScriptService { changes[uri] = change.textChanges.map(({ span, newText }): TextEdit => ({ range: { start: ts.getLineAndCharacterOfPosition(sourceFile, span.start), - end: ts.getLineAndCharacterOfPosition(sourceFile, span.start + span.length) + end: ts.getLineAndCharacterOfPosition(sourceFile, span.start + span.length), }, - newText + newText, })) } @@ -1458,7 +1467,7 @@ export class TypeScriptService { // Same score for all .map(item => [1, navigateToItemToSymbolInformation(item, program, this.root)] as [number, SymbolInformation]) } else { - const queryWithoutPackage = query && omit, Partial>(query, 'package') as SymbolDescriptor + const queryWithoutPackage = query && omit(query, 'package') as SymbolDescriptor // Require at least 2 properties to match (or all if less provided) const minScore = Math.min(2, getPropertyCount(query)) const minScoreWithoutPackage = Math.min(2, getPropertyCount(queryWithoutPackage)) diff --git a/src/util.ts b/src/util.ts index 6624e98f8..a90859d91 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,5 +1,5 @@ -import { Observable } from '@reactivex/rxjs' import { escapePathComponent } from 'fast-json-patch' +import { Observable } from 'rxjs' import { compareTwoStrings } from 'string-similarity' import * as ts from 'typescript' import * as url from 'url' @@ -121,7 +121,7 @@ const globalTSPatterns = [ /node_modules\/(?:\@|%40)types\/(node|jasmine|jest|mocha)\/.*\.d\.ts$/, /(^|\/)typings\/.*\.d\.ts$/, /(^|\/)tsd\.d\.ts($|\/)/, - /(^|\/)tslib\.d\.ts$/ // for the 'synthetic reference' created by typescript when using importHelpers + /(^|\/)tslib\.d\.ts$/, // for the 'synthetic reference' created by typescript when using importHelpers ] // isGlobalTSFile returns whether or not the filename contains global