提交 1c4e72aa 编写于 作者: M Martin Aeschlimann

share TypeScipt node_module amongst extensions

上级 38c5406b
......@@ -6,6 +6,19 @@
const cp = require('child_process');
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
function npmInstall(location) {
const result = cp.spawnSync(npm, ['install'], {
cwd: location ,
stdio: 'inherit'
});
if (result.error || result.status !== 0) {
process.exit(1);
}
}
npmInstall('extensions'); // node modules shared by all extensions
const extensions = [
'vscode-api-tests',
'vscode-colorize-tests',
......@@ -20,13 +33,4 @@ const extensions = [
'html'
];
extensions.forEach(extension => {
const result = cp.spawnSync(npm, ['install'], {
cwd: `extensions/${extension}`,
stdio: 'inherit'
});
if (result.error || result.status !== 0) {
process.exit(1);
}
});
\ No newline at end of file
extensions.forEach(extension => npmInstall(`extensions/${extension}`));
\ No newline at end of file
......@@ -2,10 +2,5 @@
"name": "extension-editing",
"version": "0.0.1",
"dependencies": {
"typescript": {
"version": "1.8.10",
"from": "typescript@>=1.8.10 <2.0.0",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-1.8.10.tgz"
}
}
}
......@@ -13,13 +13,9 @@
],
"main": "./out/extension",
"scripts": {
"postinstall": "node ./postinstall",
"compile": "gulp compile-extension:extension-editing",
"watch": "gulp watch-extension:extension-editing"
},
"dependencies": {
"typescript": "^1.8.10"
},
"contributes": {
"jsonValidation": [
{
......
......@@ -9,14 +9,9 @@ import { CompletionItem, Location, SignatureHelp, SignatureInformation, Paramete
import { LanguageMode } from './languageModes';
import { getWordAtText } from '../utils/words';
import ts = require('./typescript/typescriptServices');
import { contents as libdts } from './typescript/lib-ts';
import * as ts from 'typescript';
const DEFAULT_LIB = {
NAME: 'defaultLib:lib.d.ts',
CONTENTS: libdts
};
const FILE_NAME = 'typescript://singlefile/1'; // the same 'file' is used for all contents
const FILE_NAME = 'vscode://javascript/1'; // the same 'file' is used for all contents
const JS_WORD_REGEX = /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g;
......@@ -33,15 +28,15 @@ export function getJavascriptMode(jsDocuments: LanguageModelCache<TextDocument>)
return '1'; // default lib is static
},
getScriptSnapshot: (fileName: string) => {
let text = fileName === FILE_NAME ? currentTextDocument.getText() : DEFAULT_LIB.CONTENTS;
let text = fileName === FILE_NAME ? currentTextDocument.getText() : ts.sys.readFile(fileName);
return {
getText: (start, end) => text.substring(start, end),
getLength: () => text.length,
getChangeRange: () => void 0
};
},
getCurrentDirectory: () => '',
getDefaultLibFileName: options => DEFAULT_LIB.NAME
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options)
};
let jsLanguageService = ts.createLanguageService(host);
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export declare var contents: string;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import { getJavascriptMode } from '../modes/javascriptMode';
import { TextDocument, Range, TextEdit, FormattingOptions } from 'vscode-languageserver-types';
import { getLanguageModelCache } from '../languageModelCache';
import { getLanguageService } from 'vscode-html-languageservice';
import * as embeddedSupport from '../modes/embeddedSupport';
suite('HTML Javascript Support', () => {
var htmlLanguageService = getLanguageService();
function assertCompletions(value: string, expectedProposals: string[]): void {
let offset = value.indexOf('|');
value = value.substr(0, offset) + value.substr(offset + 1);
let document = TextDocument.create('test://test/test.html', 'html', 0, value);
let documentRegions = embeddedSupport.getDocumentRegions(htmlLanguageService, document);
let embeddedJSDocuments = getLanguageModelCache<TextDocument>(10, 60, document => documentRegions.getEmbeddedDocument('javascript'));
var mode = getJavascriptMode(embeddedJSDocuments);
let position = document.positionAt(offset);
let list = mode.doComplete(document, position);
assert.ok(list);
let actualLabels = list.items.map(c => c.label).sort();
for (let expected of expectedProposals) {
assert.ok(actualLabels.indexOf(expected) !== -1, 'Not found:' + expected + ' is ' + actualLabels.join(', '));
}
}
test('Completions', function (): any {
assertCompletions('<html><script>window.|</script></html>', ['location']);
});
});
\ No newline at end of file
{
"name": "vscode-extensions",
"version": "0.0.1",
"dependencies": {
"typescript": {
"version": "2.0.10",
"from": "typescript@>=2.0.10 <3.0.0",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.0.10.tgz"
}
}
}
{
"name": "vscode-extensions",
"version": "0.0.1",
"private": true,
"description": "Dependencies shared by all extensions",
"dependencies": {
"typescript": "^2.0.10"
},
"scripts": {
"postinstall": "node ./postinstall"
}
}
......@@ -8,16 +8,27 @@
const fs = require('fs');
const path = require('path');
// delete unused typescript stuff
const root = path.dirname(require.resolve('typescript'));
function removeFile(filePath) {
try {
fs.unlinkSync(filePath);
console.log(`removed '${filePath}'`);
} catch (e) {
console.warn(e);
}
}
for (let name of fs.readdirSync(root)) {
if (name !== 'typescript.d.ts' && name !== 'typescript.js') {
try {
fs.unlinkSync(path.join(root, name));
console.log(`removed '${path.join(root, name)}'`);
} catch (e) {
console.warn(e);
}
// delete unused typescript stuff in lib folder
const libPath = path.dirname(require.resolve('typescript'));
for (let name of fs.readdirSync(libPath)) {
if (name !== 'typescript.d.ts' && name !== 'typescript.js' && name !== 'lib.es6.d.ts') {
removeFile(path.join(libPath, name));
}
}
// delete unused typescript stuff in bin folder
const binPath = path.join(path.dirname(libPath), 'bin');
for (let name of fs.readdirSync(binPath)) {
removeFile(path.join(binPath, name));
}
removeFile(path.join(path.dirname(libPath), 'Gulpfile.ts'));
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册