This commit is contained in:
Dirk Baeumer 2020-06-30 11:21:24 +02:00
Родитель 5839e367be
Коммит 49d94daa33
11 изменённых файлов: 996 добавлений и 76 удалений

20
.vscode/launch.json поставляемый
Просмотреть файл

@ -4,7 +4,21 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"request": "launch",
"type": "node",
"name": "test:lsif",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"stopOnEntry": false,
"args": ["--timeout", "999999"],
"cwd": "${workspaceRoot}/tsc",
"runtimeExecutable": null,
"runtimeArgs": [],
"env": { },
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/tsc/lib/**/*.js"],
"preLaunchTask": "npm: watch"
},
{
"type": "node",
"request": "launch",
@ -31,7 +45,6 @@
"args": [
"-p", "tsconfig.json",
"--outputFormat", "line",
"--typeAcquisition",
"--stdout"
],
"preLaunchTask": "npm: watch",
@ -228,7 +241,8 @@
"cwd": "${workspaceFolder}/../../LanguageServer/Node/jsonrpc",
"program": "${workspaceFolder}/tsc/lib/main.js",
"args": [
"-p", "tsconfig.json",
"-p", "./src/common/tsconfig.json",
"--noContents",
"--outputFormat", "line",
"--stdout"
],

791
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -20,7 +20,9 @@
"eslint": "^6.8.0",
"@typescript-eslint/parser": "^2.22.0",
"shelljs": "^0.8.3",
"rimraf": "^3.0.2"
"rimraf": "^3.0.2",
"@types/mocha": "^7.0.2",
"mocha": "^8.0.1"
},
"scripts": {
"postinstall": "cd protocol && npm install && cd ../tsc && npm install && cd ../npm && npm install && cd ../sqlite && npm install && cd ../util && npm install && cd .. && npm run symlink && cd samples/typescript && npm install && cd ../javascript && npm install && cd ../..",

Просмотреть файл

@ -1,3 +1,2 @@
import * as Is from 'is';
Is.boolean(10);
export const x: number | string = 10;
x.toString();

Просмотреть файл

@ -35,6 +35,7 @@
"watch": "node ../build/bin/tsc -b ./tsconfig.json -w",
"clean": "node ../node_modules/rimraf/bin.js lib",
"clean:all": "node ../build/bin/tsc -b ./tsconfig.json --clean",
"test": "node ../node_modules/mocha/bin/_mocha",
"prepublishOnly": "npm run clean && npm run compile:publish",
"postpublish": "node ../build/bin/post-publish.js",
"postinstall": ""

Просмотреть файл

@ -317,11 +317,20 @@ async function processProject(config: ts.ParsedCommandLine, emitter: Emitter, bu
return process.cwd();
}
},
getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options),
directoryExists: ts.sys.directoryExists,
getDefaultLibFileName: (options) => {
const result = ts.getDefaultLibFilePath(options);
return result;
},
directoryExists: (path) => {
const result = ts.sys.directoryExists(path);
return result;
},
getDirectories: ts.sys.getDirectories,
fileExists: ts.sys.fileExists,
readFile: ts.sys.readFile,
readFile: (path: string, encoding?: string): string | undefined => {
const result = ts.sys.readFile(path, encoding);
return result;
},
readDirectory: ts.sys.readDirectory
};
const languageService = ts.createLanguageService(host);

Просмотреть файл

@ -0,0 +1,30 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
//import * as assert from 'assert';
import * as os from 'os';
import { lsif } from './lsifs';
import * as ts from 'typescript';
suite('Union Types', () => {
const compilerOptions: ts.CompilerOptions = {
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES5,
lib: [ 'es6' ]
};
test('base types', () => {
const emitter = lsif('/test', new Map([
[
'/test/a.ts',
[
'export const x: number | string = 10;',
'x.toString();'
].join(os.EOL)
]
]), compilerOptions);
console.log(emitter.toString());
});
});

Просмотреть файл

@ -1,52 +0,0 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as ts from 'typescript';
export class InMemoryLanguageServiceHost implements ts.LanguageServiceHost {
private scriptSnapshots: Map<string, ts.IScriptSnapshot>;
constructor(private cwd: string, private scripts: Map<string, string>, private options: ts.CompilerOptions) {
this.scriptSnapshots = new Map();
}
public getScriptFileNames(): string[] {
return Array.from(this.scripts.keys());
}
public getCompilationSettings(): ts.CompilerOptions {
return this.options;
}
public getScriptVersion(fileName: string): string {
return '0';
}
public getProjectVersion(): string {
return '0';
}
public getScriptSnapshot(fileName: string): ts.IScriptSnapshot | undefined {
let result: ts.IScriptSnapshot | undefined = this.scriptSnapshots.get(fileName);
if (result === undefined) {
const content = this.scripts.get(fileName);
if (content === undefined) {
return undefined;
}
result = ts.ScriptSnapshot.fromString(content);
this.scriptSnapshots.set(fileName, result);
}
return result;
}
public getCurrentDirectory(): string {
return this.cwd;
}
public getDefaultLibFileName(options: ts.CompilerOptions): string {
return ts.getDefaultLibFilePath(options);
}
}

132
tsc/src/test/lsifs.ts Normal file
Просмотреть файл

@ -0,0 +1,132 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as os from 'os';
import * as ts from 'typescript';
import { Vertex, Edge, Id, Element } from 'lsif-protocol';
import { lsif as _lsif } from '../lsif';
import { Emitter } from '../emitters/emitter';
import { Builder } from '../graph';
import { URI } from 'vscode-uri';
export class InMemoryLanguageServiceHost implements ts.LanguageServiceHost {
private scriptSnapshots: Map<string, ts.IScriptSnapshot>;
constructor(private cwd: string, private scripts: Map<string, string>, private options: ts.CompilerOptions) {
this.scriptSnapshots = new Map();
}
public getScriptFileNames(): string[] {
return Array.from(this.scripts.keys());
}
public getCompilationSettings(): ts.CompilerOptions {
return this.options;
}
public getScriptVersion(fileName: string): string {
return '0';
}
public getProjectVersion(): string {
return '0';
}
public getScriptSnapshot(fileName: string): ts.IScriptSnapshot | undefined {
let result: ts.IScriptSnapshot | undefined = this.scriptSnapshots.get(fileName);
if (result === undefined) {
const content = this.scripts.get(fileName);
if (content === undefined) {
return undefined;
}
result = ts.ScriptSnapshot.fromString(content);
this.scriptSnapshots.set(fileName, result);
}
return result;
}
public getCurrentDirectory(): string {
return this.cwd;
}
public getDefaultLibFileName(options: ts.CompilerOptions): string {
const result = ts.getDefaultLibFilePath(options);
return result;
}
public directoryExists(path: string): boolean {
const result = ts.sys.directoryExists(path);
return result;
}
public getDirectories(path: string): string[] {
const result = ts.sys.getDirectories(path);
return result;
}
public fileExists(path: string): boolean {
const result = ts.sys.fileExists(path);
return result;
}
public readFile(path: string, encoding?:string): string | undefined {
const result = ts.sys.readFile(path, encoding);
return result;
}
public readDirectory(path: string): string[] {
const result = ts.sys.readDirectory(path);
return result;
}
}
class TestEmitter implements Emitter {
private sequence: Element[];
public elements: Map<Id, Element>;
constructor() {
this.sequence = [];
this.elements = new Map();
}
public start(): void {
}
emit(element: Vertex | Edge): void {
this.sequence.push(element);
this.elements.set(element.id, element);
}
public end(): void {
}
public toString(): string {
const buffer: string[] = [];
for (const element of this.sequence) {
buffer.push(JSON.stringify(element, undefined, 0));
}
return buffer.join(os.EOL);
}
}
export function lsif(cwd: string, scripts: Map<string, string>, options: ts.CompilerOptions): TestEmitter {
const emitter = new TestEmitter();
const host = new InMemoryLanguageServiceHost(cwd, scripts, options);
const languageService = ts.createLanguageService(host);
let counter = 1;
const generator = (): number => {
return counter++;
};
const builder = new Builder({ idGenerator: generator, emitSource: false });
const group = builder.vertex.group(URI.from({ scheme: 'lsif-test', path: cwd }).toString(), cwd, URI.from({ scheme: 'lsif-test', path: cwd }).toString());
_lsif(emitter, builder, languageService, [], { stdout: true, projectRoot: cwd, projectName: cwd, group: group, tsConfigFile: undefined });
return emitter;
}

Просмотреть файл

@ -3,23 +3,18 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as ts from 'typescript';
import * as assert from 'assert';
import { InMemoryLanguageServiceHost } from './hosts';
import { Builder } from '../graph';
import { lsif } from '../lsif';
import { lsif } from './lsifs';
suite('Simple Tests', () => {
test('xxx', () => {
const host = new InMemoryLanguageServiceHost('/test', new Map([
test('Single export', () => {
const emitter = lsif('/test', new Map([
['/test/a.ts', 'export const x = 10;']
]), { });
const languageService = ts.createLanguageService(host);
let counter = 1;
const generator = (): number => {
return counter++;
};
const builder = new Builder({ idGenerator: generator, emitSource: false });
const moniker = JSON.parse('{"id":13,"type":"vertex","label":"moniker","scheme":"tsc","identifier":"a:x","unique":"group","kind":"export"}');
const range = JSON.parse('{"id":15,"type":"vertex","label":"range","start":{"line":0,"character":13},"end":{"line":0,"character":14},"tag":{"type":"definition","text":"x","kind":7,"fullRange":{"start":{"line":0,"character":13},"end":{"line":0,"character":19}}}}');
assert.deepEqual(emitter.elements.get(13), moniker);
assert.deepEqual(emitter.elements.get(15), range);
});
});

Просмотреть файл

@ -4,7 +4,6 @@
"sourceMap": true,
"declaration": true,
"composite": true,
"sourceRoot": "../src",
"rootDir": "./src",
"outDir": "./lib",
"tsBuildInfoFile":"./lib/tsconfig.tsbuildInfo",