mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-21 17:19:01 +01:00
share TypeScipt node_module amongst extensions
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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;
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
44
extensions/html/server/src/test/javascriptMode.test.ts
Normal file
44
extensions/html/server/src/test/javascriptMode.test.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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']);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user