mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
consolidate all services in one file: services.ts
This commit is contained in:
@@ -1,199 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript.Services {
|
||||
export enum EndOfLineState {
|
||||
Start,
|
||||
InMultiLineCommentTrivia,
|
||||
InSingleQuoteStringLiteral,
|
||||
InDoubleQuoteStringLiteral,
|
||||
}
|
||||
|
||||
export enum TokenClass {
|
||||
Punctuation,
|
||||
Keyword,
|
||||
Operator,
|
||||
Comment,
|
||||
Whitespace,
|
||||
Identifier,
|
||||
NumberLiteral,
|
||||
StringLiteral,
|
||||
RegExpLiteral,
|
||||
}
|
||||
|
||||
export interface ClassificationResult {
|
||||
finalLexState: EndOfLineState;
|
||||
entries: ClassificationInfo[];
|
||||
}
|
||||
|
||||
export interface ClassificationInfo {
|
||||
length: number;
|
||||
classification: TokenClass;
|
||||
}
|
||||
|
||||
export interface Classifier {
|
||||
getClassificationsForLine(text: string, lexState: EndOfLineState): ClassificationResult;
|
||||
}
|
||||
|
||||
export function createClassifier(host: Logger): Classifier {
|
||||
var scanner: TypeScript.Scanner.IScanner;
|
||||
var lastDiagnosticKey: string = null;
|
||||
var noRegexTable: boolean[];
|
||||
var reportDiagnostic = (position: number, fullWidth: number, key: string, args: any[]) => {
|
||||
lastDiagnosticKey = key;
|
||||
};
|
||||
|
||||
if (!noRegexTable) {
|
||||
noRegexTable= [];
|
||||
noRegexTable[TypeScript.SyntaxKind.IdentifierName] = true;
|
||||
noRegexTable[TypeScript.SyntaxKind.StringLiteral] = true;
|
||||
noRegexTable[TypeScript.SyntaxKind.NumericLiteral] = true;
|
||||
noRegexTable[TypeScript.SyntaxKind.RegularExpressionLiteral] = true;
|
||||
noRegexTable[TypeScript.SyntaxKind.ThisKeyword] = true;
|
||||
noRegexTable[TypeScript.SyntaxKind.PlusPlusToken] = true;
|
||||
noRegexTable[TypeScript.SyntaxKind.MinusMinusToken] = true;
|
||||
noRegexTable[TypeScript.SyntaxKind.CloseParenToken] = true;
|
||||
noRegexTable[TypeScript.SyntaxKind.CloseBracketToken] = true;
|
||||
noRegexTable[TypeScript.SyntaxKind.CloseBraceToken] = true;
|
||||
noRegexTable[TypeScript.SyntaxKind.TrueKeyword] = true;
|
||||
noRegexTable[TypeScript.SyntaxKind.FalseKeyword] = true;
|
||||
}
|
||||
|
||||
function getClassificationsForLine(text: string, lexState: EndOfLineState): ClassificationResult {
|
||||
var offset = 0;
|
||||
if (lexState !== EndOfLineState.Start) {
|
||||
// If we're in a string literal, then prepend: "\
|
||||
// (and a newline). That way when we lex we'll think we're still in a string literal.
|
||||
//
|
||||
// If we're in a multiline comment, then prepend: /*
|
||||
// (and a newline). That way when we lex we'll think we're still in a multiline comment.
|
||||
if (lexState === EndOfLineState.InDoubleQuoteStringLiteral) {
|
||||
text = '"\\\n' + text;
|
||||
}
|
||||
else if (lexState === EndOfLineState.InSingleQuoteStringLiteral) {
|
||||
text = "'\\\n" + text;
|
||||
}
|
||||
else if (lexState === EndOfLineState.InMultiLineCommentTrivia) {
|
||||
text = "/*\n" + text;
|
||||
}
|
||||
|
||||
offset = 3;
|
||||
}
|
||||
|
||||
var result = {
|
||||
finalLexState: EndOfLineState.Start,
|
||||
entries: []
|
||||
};
|
||||
|
||||
var simpleText = TypeScript.SimpleText.fromString(text);
|
||||
scanner = Scanner.createScanner(ts.ScriptTarget.ES5, simpleText, reportDiagnostic);
|
||||
|
||||
var lastTokenKind = TypeScript.SyntaxKind.None;
|
||||
var token: ISyntaxToken = null;
|
||||
do {
|
||||
lastDiagnosticKey = null;
|
||||
|
||||
token = scanner.scan(!noRegexTable[lastTokenKind]);
|
||||
lastTokenKind = token.kind();
|
||||
|
||||
processToken(text, simpleText, offset, token, result);
|
||||
}
|
||||
while (token.kind() !== SyntaxKind.EndOfFileToken);
|
||||
|
||||
lastDiagnosticKey = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
function processToken(text: string, simpleText: ISimpleText, offset: number, token: TypeScript.ISyntaxToken, result: ClassificationResult): void {
|
||||
processTriviaList(text, offset, token.leadingTrivia(simpleText), result);
|
||||
addResult(text, offset, result, width(token), token.kind());
|
||||
processTriviaList(text, offset, token.trailingTrivia(simpleText), result);
|
||||
|
||||
if (fullEnd(token) >= text.length) {
|
||||
// We're at the end.
|
||||
if (lastDiagnosticKey === TypeScript.DiagnosticCode.AsteriskSlash_expected) {
|
||||
result.finalLexState = EndOfLineState.InMultiLineCommentTrivia;
|
||||
return;
|
||||
}
|
||||
|
||||
if (token.kind() === TypeScript.SyntaxKind.StringLiteral) {
|
||||
var tokenText = token.text();
|
||||
if (tokenText.length > 0 && tokenText.charCodeAt(tokenText.length - 1) === TypeScript.CharacterCodes.backslash) {
|
||||
var quoteChar = tokenText.charCodeAt(0);
|
||||
result.finalLexState = quoteChar === TypeScript.CharacterCodes.doubleQuote
|
||||
? EndOfLineState.InDoubleQuoteStringLiteral
|
||||
: EndOfLineState.InSingleQuoteStringLiteral;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function processTriviaList(text: string, offset: number, triviaList: TypeScript.ISyntaxTriviaList, result: ClassificationResult): void {
|
||||
for (var i = 0, n = triviaList.count(); i < n; i++) {
|
||||
var trivia = triviaList.syntaxTriviaAt(i);
|
||||
addResult(text, offset, result, trivia.fullWidth(), trivia.kind());
|
||||
}
|
||||
}
|
||||
|
||||
function addResult(text: string, offset: number, result: ClassificationResult, length: number, kind: TypeScript.SyntaxKind): void {
|
||||
if (length > 0) {
|
||||
// If this is the first classification we're adding to the list, then remove any
|
||||
// offset we have if we were continuing a construct from the previous line.
|
||||
if (result.entries.length === 0) {
|
||||
length -= offset;
|
||||
}
|
||||
|
||||
result.entries.push({ length: length, classification: classFromKind(kind) });
|
||||
}
|
||||
}
|
||||
|
||||
function classFromKind(kind: TypeScript.SyntaxKind) {
|
||||
if (TypeScript.SyntaxFacts.isAnyKeyword(kind)) {
|
||||
return TokenClass.Keyword;
|
||||
}
|
||||
else if (TypeScript.SyntaxFacts.isBinaryExpressionOperatorToken(kind) ||
|
||||
TypeScript.SyntaxFacts.isPrefixUnaryExpressionOperatorToken(kind)) {
|
||||
return TokenClass.Operator;
|
||||
}
|
||||
else if (TypeScript.SyntaxFacts.isAnyPunctuation(kind)) {
|
||||
return TokenClass.Punctuation;
|
||||
}
|
||||
|
||||
switch (kind) {
|
||||
case TypeScript.SyntaxKind.WhitespaceTrivia:
|
||||
return TokenClass.Whitespace;
|
||||
case TypeScript.SyntaxKind.MultiLineCommentTrivia:
|
||||
case TypeScript.SyntaxKind.SingleLineCommentTrivia:
|
||||
return TokenClass.Comment;
|
||||
case TypeScript.SyntaxKind.NumericLiteral:
|
||||
return TokenClass.NumberLiteral;
|
||||
case TypeScript.SyntaxKind.StringLiteral:
|
||||
return TokenClass.StringLiteral;
|
||||
case TypeScript.SyntaxKind.RegularExpressionLiteral:
|
||||
return TokenClass.RegExpLiteral;
|
||||
case TypeScript.SyntaxKind.IdentifierName:
|
||||
default:
|
||||
return TokenClass.Identifier;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
getClassificationsForLine: getClassificationsForLine
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
module TypeScript {
|
||||
class Base64Format {
|
||||
static encodedValues = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||
static encode(inValue: number) {
|
||||
if (inValue < 64) {
|
||||
return Base64Format.encodedValues.charAt(inValue);
|
||||
}
|
||||
throw TypeError(inValue + ": not a 64 based value");
|
||||
}
|
||||
|
||||
static decodeChar(inChar: string) {
|
||||
if (inChar.length === 1) {
|
||||
return Base64Format.encodedValues.indexOf(inChar);
|
||||
}
|
||||
else {
|
||||
throw TypeError('"' + inChar + '" must have length 1');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class Base64VLQFormat {
|
||||
static encode(inValue: number) {
|
||||
// Add a new least significant bit that has the sign of the value.
|
||||
// if negative number the least significant bit that gets added to the number has value 1
|
||||
// else least significant bit value that gets added is 0
|
||||
// eg. -1 changes to binary : 01 [1] => 3
|
||||
// +1 changes to binary : 01 [0] => 2
|
||||
if (inValue < 0) {
|
||||
inValue = ((-inValue) << 1) + 1;
|
||||
}
|
||||
else {
|
||||
inValue = inValue << 1;
|
||||
}
|
||||
|
||||
// Encode 5 bits at a time starting from least significant bits
|
||||
var encodedStr = "";
|
||||
do {
|
||||
var currentDigit = inValue & 31; // 11111
|
||||
inValue = inValue >> 5;
|
||||
if (inValue > 0) {
|
||||
// There are still more digits to decode, set the msb (6th bit)
|
||||
currentDigit = currentDigit | 32;
|
||||
}
|
||||
encodedStr = encodedStr + Base64Format.encode(currentDigit);
|
||||
} while (inValue > 0);
|
||||
|
||||
return encodedStr;
|
||||
}
|
||||
|
||||
static decode(inString: string) {
|
||||
var result = 0;
|
||||
var negative = false;
|
||||
|
||||
var shift = 0;
|
||||
for (var i = 0; i < inString.length; i++) {
|
||||
var byte = Base64Format.decodeChar(inString[i]);
|
||||
if (i === 0) {
|
||||
// Sign bit appears in the LSBit of the first value
|
||||
if ((byte & 1) === 1) {
|
||||
negative = true;
|
||||
}
|
||||
result = (byte >> 1) & 15; // 1111x
|
||||
}
|
||||
else {
|
||||
result = result | ((byte & 31) << shift); // 11111
|
||||
}
|
||||
|
||||
shift += (i === 0) ? 4 : 5;
|
||||
|
||||
if ((byte & 32) === 32) {
|
||||
// Continue
|
||||
}
|
||||
else {
|
||||
return { value: negative ? -(result) : result, rest: inString.substr(i + 1) };
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(getDiagnosticMessage(DiagnosticCode.Base64_value_0_finished_with_a_continuation_bit, [inString]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export interface IncrementalParse {
|
||||
(oldSyntaxTree: SyntaxTree, textChangeRange: TextChangeRange, newText: ISimpleText): SyntaxTree
|
||||
}
|
||||
|
||||
|
||||
export class Document {
|
||||
private _bloomFilter: BloomFilter = null;
|
||||
|
||||
// By default, our Document class doesn't support incremental update of its contents.
|
||||
// However, we enable other layers (like teh services layer) to inject the capability
|
||||
// into us by setting this function.
|
||||
public static incrementalParse: IncrementalParse = null;
|
||||
|
||||
constructor(private compilationSettings: ts.CompilerOptions,
|
||||
public filename: string,
|
||||
public referencedFiles: string[],
|
||||
private _scriptSnapshot: IScriptSnapshot,
|
||||
public byteOrderMark: ts.ByteOrderMark,
|
||||
public version: number,
|
||||
public isOpen: boolean,
|
||||
private _syntaxTree: SyntaxTree,
|
||||
private _soruceFile: ts.SourceFile) {
|
||||
}
|
||||
|
||||
public isDeclareFile(): boolean {
|
||||
return isDTSFile(this.filename);
|
||||
}
|
||||
|
||||
public sourceUnit(): SourceUnitSyntax {
|
||||
// If we don't have a script, create one from our parse tree.
|
||||
return this.syntaxTree().sourceUnit();
|
||||
}
|
||||
|
||||
public diagnostics(): Diagnostic[] {
|
||||
return this.syntaxTree().diagnostics();
|
||||
}
|
||||
|
||||
public lineMap(): LineMap {
|
||||
return this.syntaxTree().lineMap();
|
||||
}
|
||||
|
||||
public syntaxTree(): SyntaxTree {
|
||||
if (!this._syntaxTree) {
|
||||
var start = new Date().getTime();
|
||||
|
||||
this._syntaxTree = Parser.parse(
|
||||
this.filename, SimpleText.fromScriptSnapshot(this._scriptSnapshot), this.compilationSettings.target, this.isDeclareFile());
|
||||
|
||||
var time = new Date().getTime() - start;
|
||||
|
||||
//TypeScript.syntaxTreeParseTime += time;
|
||||
}
|
||||
|
||||
return this._syntaxTree;
|
||||
}
|
||||
|
||||
public sourceFile(): ts.SourceFile {
|
||||
if (!this._soruceFile) {
|
||||
var start = new Date().getTime();
|
||||
|
||||
this._soruceFile = ts.createSourceFile(this.filename, this._scriptSnapshot.getText(0, this._scriptSnapshot.getLength()), this.compilationSettings.target);
|
||||
|
||||
var time = new Date().getTime() - start;
|
||||
|
||||
//TypeScript.astParseTime += time;
|
||||
}
|
||||
|
||||
return this._soruceFile;
|
||||
}
|
||||
|
||||
public bloomFilter(): BloomFilter {
|
||||
if (!this._bloomFilter) {
|
||||
var identifiers = createIntrinsicsObject<boolean>();
|
||||
var pre = function (cur: TypeScript.ISyntaxElement) {
|
||||
if (ASTHelpers.isValidAstNode(cur)) {
|
||||
if (cur.kind() === SyntaxKind.IdentifierName) {
|
||||
var nodeText = tokenValueText((<TypeScript.ISyntaxToken>cur));
|
||||
|
||||
identifiers[nodeText] = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TypeScript.getAstWalkerFactory().simpleWalk(this.sourceUnit(), pre, null, identifiers);
|
||||
|
||||
var identifierCount = 0;
|
||||
for (var name in identifiers) {
|
||||
if (identifiers[name]) {
|
||||
identifierCount++;
|
||||
}
|
||||
}
|
||||
|
||||
this._bloomFilter = new BloomFilter(identifierCount);
|
||||
this._bloomFilter.addKeys(identifiers);
|
||||
}
|
||||
return this._bloomFilter;
|
||||
}
|
||||
|
||||
// Returns true if this file should get emitted into its own unique output file.
|
||||
// Otherwise, it should be written into a single output file along with the rest of hte
|
||||
// documents in the compilation.
|
||||
public emitToOwnOutputFile(): boolean {
|
||||
// If we haven't specified an output file in our settings, then we're definitely
|
||||
// emitting to our own file. Also, if we're an external module, then we're
|
||||
// definitely emitting to our own file.
|
||||
return !this.compilationSettings.out || this.syntaxTree().isExternalModule();
|
||||
}
|
||||
|
||||
public update(scriptSnapshot: IScriptSnapshot, version: number, isOpen: boolean, textChangeRange: TextChangeRange): Document {
|
||||
// See if we are currently holding onto a syntax tree. We may not be because we're
|
||||
// either a closed file, or we've just been lazy and haven't had to create the syntax
|
||||
// tree yet. Access the field instead of the method so we don't accidently realize
|
||||
// the old syntax tree.
|
||||
var oldSyntaxTree = this._syntaxTree;
|
||||
|
||||
if (textChangeRange !== null && Debug.shouldAssert(AssertionLevel.Normal)) {
|
||||
var oldText = this._scriptSnapshot;
|
||||
var newText = scriptSnapshot;
|
||||
|
||||
TypeScript.Debug.assert((oldText.getLength() - textChangeRange.span().length() + textChangeRange.newLength()) === newText.getLength());
|
||||
|
||||
if (Debug.shouldAssert(AssertionLevel.VeryAggressive)) {
|
||||
var oldTextPrefix = oldText.getText(0, textChangeRange.span().start());
|
||||
var newTextPrefix = newText.getText(0, textChangeRange.span().start());
|
||||
TypeScript.Debug.assert(oldTextPrefix === newTextPrefix);
|
||||
|
||||
var oldTextSuffix = oldText.getText(textChangeRange.span().end(), oldText.getLength());
|
||||
var newTextSuffix = newText.getText(textChangeRange.newSpan().end(), newText.getLength());
|
||||
TypeScript.Debug.assert(oldTextSuffix === newTextSuffix);
|
||||
}
|
||||
}
|
||||
|
||||
var text = SimpleText.fromScriptSnapshot(scriptSnapshot);
|
||||
|
||||
// If we don't have a text change, or we don't have an old syntax tree, then do a full
|
||||
// parse. Otherwise, do an incremental parse.
|
||||
var newSyntaxTree = textChangeRange === null || oldSyntaxTree === null || Document.incrementalParse === null
|
||||
? TypeScript.Parser.parse(this.filename, text, this.compilationSettings.target, TypeScript.isDTSFile(this.filename))
|
||||
: Document.incrementalParse(oldSyntaxTree, textChangeRange, text);
|
||||
|
||||
return new Document(this.compilationSettings, this.filename, this.referencedFiles, scriptSnapshot, this.byteOrderMark, version, isOpen, newSyntaxTree, /*soruceFile*/ null);
|
||||
}
|
||||
|
||||
public static create(compilationSettings: ts.CompilerOptions, fileName: string, scriptSnapshot: IScriptSnapshot, byteOrderMark: ts.ByteOrderMark, version: number, isOpen: boolean, referencedFiles: string[]): Document {
|
||||
return new Document(compilationSettings, fileName, referencedFiles, scriptSnapshot, byteOrderMark, version, isOpen, /*syntaxTree:*/ null, /*soruceFile*/ null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
///<reference path="references.ts" />
|
||||
|
||||
module TypeScript.Services {
|
||||
// Inject support for incremental parsing to the core compiler Document class.
|
||||
Document.incrementalParse = IncrementalParser.parse;
|
||||
}
|
||||
@@ -1,357 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript.Services {
|
||||
|
||||
//
|
||||
// Public interface of the host of a language service instance.
|
||||
//
|
||||
export interface LanguageServiceHost extends TypeScript.Logger, TypeScript.IReferenceResolverHost {
|
||||
getCompilationSettings(): ts.CompilerOptions;
|
||||
getScriptFileNames(): string[];
|
||||
getScriptVersion(fileName: string): number;
|
||||
getScriptIsOpen(fileName: string): boolean;
|
||||
getScriptByteOrderMark(fileName: string): ts.ByteOrderMark;
|
||||
getScriptSnapshot(fileName: string): TypeScript.IScriptSnapshot;
|
||||
getLocalizedDiagnosticMessages(): any;
|
||||
getCancellationToken(): ts.CancellationToken;
|
||||
}
|
||||
|
||||
//
|
||||
// Public services of a language service instance associated
|
||||
// with a language service host instance
|
||||
//
|
||||
export interface LanguageService {
|
||||
// Note: refresh is a no-op now. It is only around for back compat purposes.
|
||||
refresh(): void;
|
||||
|
||||
cleanupSemanticCache(): void;
|
||||
|
||||
getSyntacticDiagnostics(fileName: string): ts.Diagnostic[];
|
||||
getSemanticDiagnostics(fileName: string): ts.Diagnostic[];
|
||||
getCompilerOptionsDiagnostics(): ts.Diagnostic[];
|
||||
|
||||
getCompletionsAtPosition(fileName: string, position: number, isMemberCompletion: boolean): CompletionInfo;
|
||||
getCompletionEntryDetails(fileName: string, position: number, entryName: string): CompletionEntryDetails;
|
||||
|
||||
getTypeAtPosition(fileName: string, position: number): TypeInfo;
|
||||
|
||||
getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): SpanInfo;
|
||||
|
||||
getBreakpointStatementAtPosition(fileName: string, position: number): SpanInfo;
|
||||
|
||||
getSignatureAtPosition(fileName: string, position: number): SignatureInfo;
|
||||
|
||||
getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[];
|
||||
getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[];
|
||||
getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[];
|
||||
getImplementorsAtPosition(fileName: string, position: number): ReferenceEntry[];
|
||||
|
||||
getNavigateToItems(searchValue: string): NavigateToItem[];
|
||||
getScriptLexicalStructure(fileName: string): NavigateToItem[];
|
||||
|
||||
getOutliningRegions(fileName: string): TypeScript.TextSpan[];
|
||||
getBraceMatchingAtPosition(fileName: string, position: number): TypeScript.TextSpan[];
|
||||
getIndentationAtPosition(fileName: string, position: number, options: TypeScript.Services.EditorOptions): number;
|
||||
|
||||
getFormattingEditsForRange(fileName: string, minChar: number, limChar: number, options: FormatCodeOptions): TextEdit[];
|
||||
getFormattingEditsForDocument(fileName: string, minChar: number, limChar: number, options: FormatCodeOptions): TextEdit[];
|
||||
getFormattingEditsOnPaste(fileName: string, minChar: number, limChar: number, options: FormatCodeOptions): TextEdit[];
|
||||
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextEdit[];
|
||||
|
||||
getEmitOutput(fileName: string): EmitOutput;
|
||||
|
||||
//getSyntaxTree(fileName: string): TypeScript.SyntaxTree;
|
||||
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
export function logInternalError(logger: TypeScript.Logger, err: Error) {
|
||||
logger.log("*INTERNAL ERROR* - Exception in typescript services: " + err.message);
|
||||
}
|
||||
|
||||
export interface ReferenceEntry {
|
||||
fileName: string;
|
||||
minChar: number;
|
||||
limChar: number;
|
||||
isWriteAccess: boolean;
|
||||
}
|
||||
|
||||
export interface NavigateToItem {
|
||||
name: string;
|
||||
kind: string; // see ScriptElementKind
|
||||
kindModifiers: string; // see ScriptElementKindModifier, comma separated
|
||||
matchKind: string;
|
||||
fileName: string;
|
||||
minChar: number;
|
||||
limChar: number;
|
||||
additionalSpans?: SpanInfo[];
|
||||
containerName: string;
|
||||
containerKind: string; // see ScriptElementKind
|
||||
}
|
||||
|
||||
export class TextEdit {
|
||||
constructor(public minChar: number, public limChar: number, public text: string) {
|
||||
}
|
||||
|
||||
static createInsert(pos: number, text: string): TextEdit {
|
||||
return new TextEdit(pos, pos, text);
|
||||
}
|
||||
static createDelete(minChar: number, limChar: number): TextEdit {
|
||||
return new TextEdit(minChar, limChar, "");
|
||||
}
|
||||
static createReplace(minChar: number, limChar: number, text: string): TextEdit {
|
||||
return new TextEdit(minChar, limChar, text);
|
||||
}
|
||||
}
|
||||
|
||||
export class EditorOptions {
|
||||
public IndentSize: number = 4;
|
||||
public TabSize: number = 4;
|
||||
public NewLineCharacter: string = "\r\n";
|
||||
public ConvertTabsToSpaces: boolean = true;
|
||||
|
||||
public static clone(objectToClone: EditorOptions): EditorOptions {
|
||||
var editorOptions = new EditorOptions();
|
||||
editorOptions.IndentSize = objectToClone.IndentSize;
|
||||
editorOptions.TabSize = objectToClone.TabSize;
|
||||
editorOptions.NewLineCharacter = objectToClone.NewLineCharacter;
|
||||
editorOptions.ConvertTabsToSpaces = objectToClone.ConvertTabsToSpaces;
|
||||
return editorOptions;
|
||||
}
|
||||
}
|
||||
|
||||
export class FormatCodeOptions extends EditorOptions {
|
||||
public InsertSpaceAfterCommaDelimiter: boolean = true;
|
||||
public InsertSpaceAfterSemicolonInForStatements: boolean = true;
|
||||
public InsertSpaceBeforeAndAfterBinaryOperators: boolean = true;
|
||||
public InsertSpaceAfterKeywordsInControlFlowStatements: boolean = true;
|
||||
public InsertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean = false;
|
||||
public InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean = false;
|
||||
public PlaceOpenBraceOnNewLineForFunctions: boolean = false;
|
||||
public PlaceOpenBraceOnNewLineForControlBlocks: boolean = false;
|
||||
|
||||
public static clone(objectToClone: FormatCodeOptions ): FormatCodeOptions {
|
||||
var formatCodeOptions = <FormatCodeOptions>EditorOptions.clone(objectToClone);
|
||||
formatCodeOptions.InsertSpaceAfterCommaDelimiter = objectToClone.InsertSpaceAfterCommaDelimiter;
|
||||
formatCodeOptions.InsertSpaceAfterSemicolonInForStatements = objectToClone.InsertSpaceAfterSemicolonInForStatements;
|
||||
formatCodeOptions.InsertSpaceBeforeAndAfterBinaryOperators = objectToClone.InsertSpaceBeforeAndAfterBinaryOperators;
|
||||
formatCodeOptions.InsertSpaceAfterKeywordsInControlFlowStatements = objectToClone.InsertSpaceAfterKeywordsInControlFlowStatements;
|
||||
formatCodeOptions.InsertSpaceAfterFunctionKeywordForAnonymousFunctions = objectToClone.InsertSpaceAfterFunctionKeywordForAnonymousFunctions;
|
||||
formatCodeOptions.InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis = objectToClone.InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis;
|
||||
formatCodeOptions.PlaceOpenBraceOnNewLineForFunctions = objectToClone.PlaceOpenBraceOnNewLineForFunctions;
|
||||
formatCodeOptions.PlaceOpenBraceOnNewLineForControlBlocks = objectToClone.PlaceOpenBraceOnNewLineForControlBlocks;
|
||||
return formatCodeOptions;
|
||||
}
|
||||
}
|
||||
|
||||
export interface DefinitionInfo {
|
||||
fileName: string;
|
||||
minChar: number;
|
||||
limChar: number;
|
||||
kind: string;
|
||||
name: string;
|
||||
containerKind: string;
|
||||
containerName: string;
|
||||
}
|
||||
|
||||
export interface TypeInfo {
|
||||
memberName: TypeScript.MemberName;
|
||||
docComment: string;
|
||||
fullSymbolName: string;
|
||||
kind: string;
|
||||
minChar: number;
|
||||
limChar: number;
|
||||
}
|
||||
|
||||
export interface SpanInfo {
|
||||
minChar: number;
|
||||
limChar: number;
|
||||
// text?: string;
|
||||
}
|
||||
|
||||
export interface SignatureInfo {
|
||||
actual: ActualSignatureInfo;
|
||||
formal: FormalSignatureItemInfo[]; // Formal signatures
|
||||
activeFormal: number; // Index of the "best match" formal signature
|
||||
}
|
||||
|
||||
export interface FormalSignatureItemInfo {
|
||||
signatureInfo: string;
|
||||
typeParameters: FormalTypeParameterInfo[];
|
||||
parameters: FormalParameterInfo[]; // Array of parameters
|
||||
docComment: string; // Help for the signature
|
||||
}
|
||||
|
||||
export interface FormalTypeParameterInfo {
|
||||
name: string; // Type parameter name
|
||||
docComment: string; // Comments that contain help for the parameter
|
||||
minChar: number; // minChar for parameter info in the formal signature info string
|
||||
limChar: number; // lim char for parameter info in the formal signature info string
|
||||
}
|
||||
|
||||
export interface FormalParameterInfo {
|
||||
name: string; // Parameter name
|
||||
isVariable: boolean; // true if parameter is var args
|
||||
docComment: string; // Comments that contain help for the parameter
|
||||
minChar: number; // minChar for parameter info in the formal signature info string
|
||||
limChar: number; // lim char for parameter info in the formal signature info string
|
||||
}
|
||||
|
||||
export interface ActualSignatureInfo {
|
||||
parameterMinChar: number;
|
||||
parameterLimChar: number;
|
||||
currentParameterIsTypeParameter: boolean; // current parameter is a type argument or a normal argument
|
||||
currentParameter: number; // Index of active parameter in "parameters" or "typeParamters" array
|
||||
}
|
||||
|
||||
export interface CompletionInfo {
|
||||
isMemberCompletion: boolean;
|
||||
entries: CompletionEntry[];
|
||||
}
|
||||
|
||||
export interface CompletionEntry {
|
||||
name: string;
|
||||
kind: string; // see ScriptElementKind
|
||||
kindModifiers: string; // see ScriptElementKindModifier, comma separated
|
||||
}
|
||||
|
||||
export interface CompletionEntryDetails {
|
||||
name: string;
|
||||
kind: string; // see ScriptElementKind
|
||||
kindModifiers: string; // see ScriptElementKindModifier, comma separated
|
||||
type: string;
|
||||
fullSymbolName: string;
|
||||
docComment: string;
|
||||
}
|
||||
|
||||
export enum EmitOutputResult {
|
||||
Succeeded,
|
||||
FailedBecauseOfSyntaxErrors,
|
||||
FailedBecauseOfCompilerOptionsErrors,
|
||||
FailedToGenerateDeclarationsBecauseOfSemanticErrors
|
||||
}
|
||||
|
||||
export interface EmitOutput {
|
||||
outputFiles: OutputFile[];
|
||||
emitOutputResult: EmitOutputResult;
|
||||
}
|
||||
|
||||
export enum OutputFileType {
|
||||
JavaScript,
|
||||
SourceMap,
|
||||
Declaration
|
||||
}
|
||||
|
||||
export interface OutputFile {
|
||||
name: string;
|
||||
writeByteOrderMark: boolean;
|
||||
text: string;
|
||||
fileType: OutputFileType;
|
||||
sourceMapOutput: any;
|
||||
}
|
||||
|
||||
// TODO: move these to enums
|
||||
export class ScriptElementKind {
|
||||
static unknown = "";
|
||||
|
||||
// predefined type (void) or keyword (class)
|
||||
static keyword = "keyword";
|
||||
|
||||
// top level script node
|
||||
static scriptElement = "script";
|
||||
|
||||
// module foo {}
|
||||
static moduleElement = "module";
|
||||
|
||||
// class X {}
|
||||
static classElement = "class";
|
||||
|
||||
// interface Y {}
|
||||
static interfaceElement = "interface";
|
||||
|
||||
// enum E
|
||||
static enumElement = "enum";
|
||||
|
||||
// Inside module and script only
|
||||
// var v = ..
|
||||
static variableElement = "var";
|
||||
|
||||
// Inside function
|
||||
static localVariableElement = "local var";
|
||||
|
||||
// Inside module and script only
|
||||
// function f() { }
|
||||
static functionElement = "function";
|
||||
|
||||
// Inside function
|
||||
static localFunctionElement = "local function";
|
||||
|
||||
// class X { [public|private]* foo() {} }
|
||||
static memberFunctionElement = "method";
|
||||
|
||||
// class X { [public|private]* [get|set] foo:number; }
|
||||
static memberGetAccessorElement = "getter";
|
||||
static memberSetAccessorElement = "setter";
|
||||
|
||||
// class X { [public|private]* foo:number; }
|
||||
// interface Y { foo:number; }
|
||||
static memberVariableElement = "property";
|
||||
|
||||
// class X { constructor() { } }
|
||||
static constructorImplementationElement = "constructor";
|
||||
|
||||
// interface Y { ():number; }
|
||||
static callSignatureElement = "call";
|
||||
|
||||
// interface Y { []:number; }
|
||||
static indexSignatureElement = "index";
|
||||
|
||||
// interface Y { new():Y; }
|
||||
static constructSignatureElement = "construct";
|
||||
|
||||
// function foo(*Y*: string)
|
||||
static parameterElement = "parameter";
|
||||
|
||||
static typeParameterElement = "type parameter";
|
||||
|
||||
static primitiveType = "primitive type";
|
||||
}
|
||||
|
||||
export class ScriptElementKindModifier {
|
||||
static none = "";
|
||||
static publicMemberModifier = "public";
|
||||
static privateMemberModifier = "private";
|
||||
static exportedModifier = "export";
|
||||
static ambientModifier = "declare";
|
||||
static staticModifier = "static";
|
||||
}
|
||||
|
||||
export class MatchKind {
|
||||
static none: string = null;
|
||||
static exact = "exact";
|
||||
static subString = "substring";
|
||||
static prefix = "prefix";
|
||||
}
|
||||
|
||||
export class DiagnosticCategory {
|
||||
static none = "";
|
||||
static error = "error";
|
||||
static warning = "warning";
|
||||
static message = "message";
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -20,32 +20,14 @@
|
||||
/// <reference path='text\references.ts' />
|
||||
/// <reference path='syntax\references.ts' />
|
||||
|
||||
/// <reference path='syntax\incrementalParser.ts' />
|
||||
|
||||
/// <reference path='classifier.ts' />
|
||||
/// <reference path='languageService.ts' />
|
||||
/// <reference path='pullLanguageService.ts' />
|
||||
/// <reference path='shims.ts' />
|
||||
|
||||
/// <reference path='outliningElementsCollector.ts' />
|
||||
/// <reference path='GetScriptLexicalStructureWalker.ts' />
|
||||
/// <reference path='BraceMatcher.ts' />
|
||||
/// <reference path='Breakpoints.ts' />
|
||||
/// <reference path='indentation.ts' />
|
||||
/// <reference path='formatting\formatting.ts' />
|
||||
/// <reference path='completionHelpers.ts' />
|
||||
/// <reference path='keywordCompletions.ts' />
|
||||
|
||||
|
||||
/// <reference path='compiler\document.ts' />
|
||||
/// <reference path='compiler\diagnostics.ts' />
|
||||
/// <reference path='compiler\hashTable.ts' />
|
||||
/// <reference path='compiler\base64.ts' />
|
||||
/// <reference path='compiler\pathUtils.ts' />
|
||||
/// <reference path='compiler\referenceResolution.ts' />
|
||||
/// <reference path='compiler\precompile.ts' />
|
||||
/// <reference path='compiler\bloomFilter.ts' />
|
||||
/// <reference path='compiler\flags.ts' />
|
||||
/// <reference path='compiler\types.ts' />
|
||||
/// <reference path='compiler\ast.ts' />
|
||||
/// <reference path='compiler\astWalker.ts' />
|
||||
|
||||
Reference in New Issue
Block a user