mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into sourceFileUpdate
Conflicts: src/compiler/parser.ts src/services/formatting/tokenSpan.ts src/services/text.ts
This commit is contained in:
@@ -1,152 +0,0 @@
|
||||
// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0.
|
||||
// See LICENSE.txt in the project root for complete license information.
|
||||
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript.Services {
|
||||
export class FindReferenceHelpers {
|
||||
public static compareSymbolsForLexicalIdentity(firstSymbol: TypeScript.PullSymbol, secondSymbol: TypeScript.PullSymbol): boolean {
|
||||
// Unwrap modules so that we're always referring to the variable.
|
||||
if (!firstSymbol.isAlias() && firstSymbol.isContainer()) {
|
||||
var containerForFirstSymbol = (<TypeScript.PullContainerSymbol>firstSymbol);
|
||||
if (containerForFirstSymbol.getInstanceSymbol()) {
|
||||
firstSymbol = containerForFirstSymbol.getInstanceSymbol();
|
||||
}
|
||||
}
|
||||
|
||||
if (!secondSymbol.isAlias() && secondSymbol.isContainer()) {
|
||||
var containerForSecondSymbol = (<TypeScript.PullContainerSymbol>secondSymbol);
|
||||
if (containerForSecondSymbol.getInstanceSymbol()) {
|
||||
secondSymbol = containerForSecondSymbol.getInstanceSymbol();
|
||||
}
|
||||
}
|
||||
|
||||
if (firstSymbol.kind === secondSymbol.kind) {
|
||||
if (firstSymbol === secondSymbol) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we have two variables and they have the same name and the same parent, then
|
||||
// they are the same symbol.
|
||||
if (firstSymbol.kind === TypeScript.PullElementKind.Variable &&
|
||||
firstSymbol.name === secondSymbol.name &&
|
||||
firstSymbol.getDeclarations() && firstSymbol.getDeclarations().length >= 1 &&
|
||||
secondSymbol.getDeclarations() && secondSymbol.getDeclarations().length >= 1) {
|
||||
|
||||
var firstSymbolDecl = firstSymbol.getDeclarations()[0];
|
||||
var secondSymbolDecl = secondSymbol.getDeclarations()[0];
|
||||
|
||||
return firstSymbolDecl.getParentDecl() === secondSymbolDecl.getParentDecl();
|
||||
}
|
||||
|
||||
// If we have two properties that belong to an object literal, then we need ot see
|
||||
// if they came from teh same object literal ast.
|
||||
if (firstSymbol.kind === TypeScript.PullElementKind.Property &&
|
||||
firstSymbol.name === secondSymbol.name &&
|
||||
firstSymbol.getDeclarations() && firstSymbol.getDeclarations().length >= 1 &&
|
||||
secondSymbol.getDeclarations() && secondSymbol.getDeclarations().length >= 1) {
|
||||
|
||||
var firstSymbolDecl = firstSymbol.getDeclarations()[0];
|
||||
var secondSymbolDecl = secondSymbol.getDeclarations()[0];
|
||||
|
||||
var firstParentDecl = firstSymbolDecl.getParentDecl();
|
||||
var secondParentDecl = secondSymbolDecl.getParentDecl();
|
||||
|
||||
if (firstParentDecl.kind === TypeScript.PullElementKind.ObjectLiteral &&
|
||||
secondParentDecl.kind === TypeScript.PullElementKind.ObjectLiteral) {
|
||||
|
||||
return firstParentDecl.ast() === secondParentDecl.ast();
|
||||
}
|
||||
}
|
||||
|
||||
// check if we are dealing with the implementation of interface method or a method override
|
||||
if (firstSymbol.name === secondSymbol.name) {
|
||||
// at this point firstSymbol.kind === secondSymbol.kind so we can pick any of those
|
||||
switch (firstSymbol.kind) {
|
||||
case PullElementKind.Property:
|
||||
case PullElementKind.Method:
|
||||
case PullElementKind.GetAccessor:
|
||||
case PullElementKind.SetAccessor:
|
||||
// these kinds can only be defined in types
|
||||
var t1 = <PullTypeSymbol>firstSymbol.getContainer();
|
||||
var t2 = <PullTypeSymbol>secondSymbol.getContainer();
|
||||
t1._resolveDeclaredSymbol();
|
||||
t2._resolveDeclaredSymbol();
|
||||
|
||||
return t1.hasBase(t2) || t2.hasBase(t1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
switch (firstSymbol.kind) {
|
||||
case TypeScript.PullElementKind.Class: {
|
||||
return this.checkSymbolsForDeclarationEquality(firstSymbol, secondSymbol);
|
||||
}
|
||||
case TypeScript.PullElementKind.Property: {
|
||||
if (firstSymbol.isAccessor()) {
|
||||
var getterSymbol = (<TypeScript.PullAccessorSymbol>firstSymbol).getGetter();
|
||||
var setterSymbol = (<TypeScript.PullAccessorSymbol>firstSymbol).getSetter();
|
||||
|
||||
if (getterSymbol && getterSymbol === secondSymbol) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (setterSymbol && setterSymbol === secondSymbol) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case TypeScript.PullElementKind.Function: {
|
||||
if (secondSymbol.isAccessor()) {
|
||||
var getterSymbol = (<TypeScript.PullAccessorSymbol>secondSymbol).getGetter();
|
||||
var setterSymbol = (<TypeScript.PullAccessorSymbol>secondSymbol).getSetter();
|
||||
|
||||
if (getterSymbol && getterSymbol === firstSymbol) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (setterSymbol && setterSymbol === firstSymbol) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case TypeScript.PullElementKind.ConstructorMethod: {
|
||||
return this.checkSymbolsForDeclarationEquality(firstSymbol, secondSymbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return firstSymbol === secondSymbol;
|
||||
}
|
||||
|
||||
private static checkSymbolsForDeclarationEquality(firstSymbol: TypeScript.PullSymbol, secondSymbol: TypeScript.PullSymbol): boolean {
|
||||
var firstSymbolDeclarations: TypeScript.PullDecl[] = firstSymbol.getDeclarations();
|
||||
var secondSymbolDeclarations: TypeScript.PullDecl[] = secondSymbol.getDeclarations();
|
||||
for (var i = 0, iLen = firstSymbolDeclarations.length; i < iLen; i++) {
|
||||
for (var j = 0, jLen = secondSymbolDeclarations.length; j < jLen; j++) {
|
||||
if (this.declarationsAreSameOrParents(firstSymbolDeclarations[i], secondSymbolDeclarations[j])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static declarationsAreSameOrParents(firstDecl: TypeScript.PullDecl, secondDecl: TypeScript.PullDecl): boolean {
|
||||
var firstParent: TypeScript.PullDecl = firstDecl.getParentDecl();
|
||||
var secondParent: TypeScript.PullDecl = secondDecl.getParentDecl();
|
||||
if (firstDecl === secondDecl ||
|
||||
firstDecl === secondParent ||
|
||||
firstParent === secondDecl ||
|
||||
firstParent === secondParent) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
///<reference path='services.ts' />
|
||||
///<reference path='formatting\indentation.ts' />
|
||||
///<reference path='formatting\formattingScanner.ts' />
|
||||
///<reference path='formatting\rulesProvider.ts' />
|
||||
///<reference path='..\services.ts' />
|
||||
///<reference path='formattingScanner.ts' />
|
||||
///<reference path='rulesProvider.ts' />
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module ts.formatting {
|
||||
|
||||
@@ -986,4 +986,56 @@ module ts.formatting {
|
||||
|
||||
return SyntaxKind.Unknown;
|
||||
}
|
||||
|
||||
var internedTabsIndentation: string[];
|
||||
var internedSpacesIndentation: string[];
|
||||
|
||||
export function getIndentationString(indentation: number, options: FormatCodeOptions): string {
|
||||
if (!options.ConvertTabsToSpaces) {
|
||||
var tabs = Math.floor(indentation / options.TabSize);
|
||||
var spaces = indentation - tabs * options.TabSize;
|
||||
|
||||
var tabString: string;
|
||||
if (!internedTabsIndentation) {
|
||||
internedTabsIndentation = [];
|
||||
}
|
||||
|
||||
if (internedTabsIndentation[tabs] === undefined) {
|
||||
internedTabsIndentation[tabs] = tabString = repeat('\t', tabs);
|
||||
}
|
||||
else {
|
||||
tabString = internedTabsIndentation[tabs];
|
||||
}
|
||||
|
||||
return spaces ? tabString + repeat(" ", spaces) : tabString;
|
||||
}
|
||||
else {
|
||||
var spacesString: string;
|
||||
var quotient = Math.floor(indentation / options.IndentSize);
|
||||
var remainder = indentation % options.IndentSize;
|
||||
if (!internedSpacesIndentation) {
|
||||
internedSpacesIndentation = [];
|
||||
}
|
||||
|
||||
if (internedSpacesIndentation[quotient] === undefined) {
|
||||
spacesString = repeat(" ", options.IndentSize * quotient);
|
||||
internedSpacesIndentation[quotient] = spacesString;
|
||||
}
|
||||
else {
|
||||
spacesString = internedSpacesIndentation[quotient];
|
||||
}
|
||||
|
||||
|
||||
return remainder ? spacesString + repeat(" ", remainder) : spacesString;
|
||||
}
|
||||
|
||||
function repeat(value: string, count: number): string {
|
||||
var s = "";
|
||||
for (var i = 0; i < count; ++i) {
|
||||
s += value;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/// <reference path="..\formatting.ts"/>
|
||||
/// <reference path="formatting.ts"/>
|
||||
/// <reference path="..\..\compiler\scanner.ts"/>
|
||||
|
||||
module ts.formatting {
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path='..\text.ts' />
|
||||
///<reference path='..\services.ts' />
|
||||
///<reference path='formattingContext.ts' />
|
||||
///<reference path='formattingRequestKind.ts' />
|
||||
@@ -25,5 +24,4 @@
|
||||
///<reference path='ruleOperationContext.ts' />
|
||||
///<reference path='rules.ts' />
|
||||
///<reference path='rulesMap.ts' />
|
||||
///<reference path='tokenRange.ts' />
|
||||
///<reference path='tokenSpan.ts' />
|
||||
///<reference path='tokenRange.ts' />
|
||||
@@ -1,4 +1,4 @@
|
||||
///<reference path='services.ts' />
|
||||
///<reference path='..\services.ts' />
|
||||
|
||||
module ts.formatting {
|
||||
export module SmartIndenter {
|
||||
@@ -1,19 +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 ts.formatting {
|
||||
}
|
||||
@@ -14,22 +14,6 @@
|
||||
//
|
||||
|
||||
module ts {
|
||||
|
||||
export interface OutliningSpan {
|
||||
/**
|
||||
* @param textSpan The span of the document to actually collapse.
|
||||
* @param hintSpan The span of the document to display when the user hovers over the
|
||||
* collapsed span.
|
||||
* @param bannerText The text to display in the editor for the collapsed region.
|
||||
* @param autoCollapse Whether or not this region should be automatically collapsed when
|
||||
* the 'Collapse to Definitions' command is invoked.
|
||||
*/
|
||||
textSpan: TextSpan;
|
||||
hintSpan: TextSpan;
|
||||
bannerText: string;
|
||||
autoCollapse: boolean;
|
||||
}
|
||||
|
||||
export module OutliningElementsCollector {
|
||||
export function collectElements(sourceFile: SourceFile): OutliningSpan[] {
|
||||
var elements: OutliningSpan[] = [];
|
||||
|
||||
+32
-187
@@ -4,14 +4,13 @@
|
||||
/// <reference path="..\compiler\parser.ts"/>
|
||||
/// <reference path="..\compiler\checker.ts"/>
|
||||
|
||||
/// <reference path='text.ts' />
|
||||
/// <reference path='breakpoints.ts' />
|
||||
/// <reference path='outliningElementsCollector.ts' />
|
||||
/// <reference path='navigationBar.ts' />
|
||||
/// <reference path='breakpoints.ts' />
|
||||
/// <reference path='signatureHelp.ts' />
|
||||
/// <reference path='utilities.ts' />
|
||||
/// <reference path='smartIndenter.ts' />
|
||||
/// <reference path='formatting.ts' />
|
||||
/// <reference path='formatting\formatting.ts' />
|
||||
/// <reference path='formatting\smartIndenter.ts' />
|
||||
|
||||
module ts {
|
||||
|
||||
@@ -862,8 +861,8 @@ module ts {
|
||||
getScriptVersion(fileName: string): string;
|
||||
getScriptIsOpen(fileName: string): boolean;
|
||||
getScriptSnapshot(fileName: string): IScriptSnapshot;
|
||||
getLocalizedDiagnosticMessages(): any;
|
||||
getCancellationToken(): CancellationToken;
|
||||
getLocalizedDiagnosticMessages?(): any;
|
||||
getCancellationToken?(): CancellationToken;
|
||||
getCurrentDirectory(): string;
|
||||
getDefaultLibFilename(options: CompilerOptions): string;
|
||||
}
|
||||
@@ -882,7 +881,7 @@ module ts {
|
||||
getSyntacticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[];
|
||||
getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[];
|
||||
|
||||
getCompletionsAtPosition(fileName: string, position: number, isMemberCompletion: boolean): CompletionInfo;
|
||||
getCompletionsAtPosition(fileName: string, position: number): CompletionInfo;
|
||||
getCompletionEntryDetails(fileName: string, position: number, entryName: string): CompletionEntryDetails;
|
||||
|
||||
getQuickInfoAtPosition(fileName: string, position: number): QuickInfo;
|
||||
@@ -918,7 +917,7 @@ module ts {
|
||||
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
|
||||
export interface ClassifiedSpan {
|
||||
textSpan: TextSpan;
|
||||
classificationType: string; // ClassificationTypeNames
|
||||
@@ -1101,6 +1100,23 @@ module ts {
|
||||
documentation: SymbolDisplayPart[];
|
||||
}
|
||||
|
||||
export interface OutliningSpan {
|
||||
/** The span of the document to actually collapse. */
|
||||
textSpan: TextSpan;
|
||||
|
||||
/** The span of the document to display when the user hovers over the collapsed span. */
|
||||
hintSpan: TextSpan;
|
||||
|
||||
/** The text to display in the editor for the collapsed region. */
|
||||
bannerText: string;
|
||||
|
||||
/**
|
||||
* Whether or not this region should be automatically collapsed when
|
||||
* the 'Collapse to Definitions' command is invoked.
|
||||
*/
|
||||
autoCollapse: boolean;
|
||||
}
|
||||
|
||||
export interface EmitOutput {
|
||||
outputFiles: OutputFile[];
|
||||
emitOutputStatus: EmitReturnStatus;
|
||||
@@ -1318,6 +1334,10 @@ module ts {
|
||||
owners: string[];
|
||||
}
|
||||
|
||||
export interface DisplayPartsSymbolWriter extends SymbolWriter {
|
||||
displayParts(): SymbolDisplayPart[];
|
||||
}
|
||||
|
||||
export function displayPartsToString(displayParts: SymbolDisplayPart[]) {
|
||||
if (displayParts) {
|
||||
return map(displayParts, displayPart => displayPart.text).join("");
|
||||
@@ -1326,100 +1346,6 @@ module ts {
|
||||
return "";
|
||||
}
|
||||
|
||||
export interface DisplayPartsSymbolWriter extends SymbolWriter {
|
||||
displayParts(): SymbolDisplayPart[];
|
||||
}
|
||||
|
||||
var displayPartWriter = getDisplayPartWriter();
|
||||
function getDisplayPartWriter(): DisplayPartsSymbolWriter {
|
||||
var displayParts: SymbolDisplayPart[];
|
||||
var lineStart: boolean;
|
||||
var indent: number;
|
||||
|
||||
resetWriter();
|
||||
return {
|
||||
displayParts: () => displayParts,
|
||||
writeKeyword: text => writeKind(text, SymbolDisplayPartKind.keyword),
|
||||
writeOperator: text => writeKind(text, SymbolDisplayPartKind.operator),
|
||||
writePunctuation: text => writeKind(text, SymbolDisplayPartKind.punctuation),
|
||||
writeSpace: text => writeKind(text, SymbolDisplayPartKind.space),
|
||||
writeStringLiteral: text => writeKind(text, SymbolDisplayPartKind.stringLiteral),
|
||||
writeParameter: text => writeKind(text, SymbolDisplayPartKind.parameterName),
|
||||
writeSymbol,
|
||||
writeLine,
|
||||
increaseIndent: () => { indent++; },
|
||||
decreaseIndent: () => { indent--; },
|
||||
clear: resetWriter,
|
||||
trackSymbol: () => { }
|
||||
};
|
||||
|
||||
function writeIndent() {
|
||||
if (lineStart) {
|
||||
var indentString = getIndentString(indent);
|
||||
if (indentString) {
|
||||
displayParts.push(displayPart(indentString, SymbolDisplayPartKind.space));
|
||||
}
|
||||
lineStart = false;
|
||||
}
|
||||
}
|
||||
|
||||
function writeKind(text: string, kind: SymbolDisplayPartKind) {
|
||||
writeIndent();
|
||||
displayParts.push(displayPart(text, kind));
|
||||
}
|
||||
|
||||
function writeSymbol(text: string, symbol: Symbol) {
|
||||
writeIndent();
|
||||
displayParts.push(symbolPart(text, symbol));
|
||||
}
|
||||
|
||||
function writeLine() {
|
||||
displayParts.push(lineBreakPart());
|
||||
lineStart = true;
|
||||
}
|
||||
|
||||
function resetWriter() {
|
||||
displayParts = []
|
||||
lineStart = true;
|
||||
indent = 0;
|
||||
}
|
||||
}
|
||||
|
||||
function displayPart(text: string, kind: SymbolDisplayPartKind, symbol?: Symbol): SymbolDisplayPart {
|
||||
return <SymbolDisplayPart> {
|
||||
text: text,
|
||||
kind: SymbolDisplayPartKind[kind]
|
||||
};
|
||||
}
|
||||
|
||||
export function spacePart() {
|
||||
return displayPart(" ", SymbolDisplayPartKind.space);
|
||||
}
|
||||
|
||||
export function keywordPart(kind: SyntaxKind) {
|
||||
return displayPart(tokenToString(kind), SymbolDisplayPartKind.keyword);
|
||||
}
|
||||
|
||||
export function punctuationPart(kind: SyntaxKind) {
|
||||
return displayPart(tokenToString(kind), SymbolDisplayPartKind.punctuation);
|
||||
}
|
||||
|
||||
export function operatorPart(kind: SyntaxKind) {
|
||||
return displayPart(tokenToString(kind), SymbolDisplayPartKind.operator);
|
||||
}
|
||||
|
||||
export function textPart(text: string) {
|
||||
return displayPart(text, SymbolDisplayPartKind.text);
|
||||
}
|
||||
|
||||
export function lineBreakPart() {
|
||||
return displayPart("\n", SymbolDisplayPartKind.lineBreak);
|
||||
}
|
||||
|
||||
function isFirstDeclarationOfSymbolParameter(symbol: Symbol) {
|
||||
return symbol.declarations && symbol.declarations.length > 0 && symbol.declarations[0].kind === SyntaxKind.Parameter;
|
||||
}
|
||||
|
||||
function isLocalVariableOrFunction(symbol: Symbol) {
|
||||
if (symbol.parent) {
|
||||
return false; // This is exported symbol
|
||||
@@ -1448,59 +1374,6 @@ module ts {
|
||||
});
|
||||
}
|
||||
|
||||
export function symbolPart(text: string, symbol: Symbol) {
|
||||
return displayPart(text, displayPartKind(symbol), symbol);
|
||||
|
||||
function displayPartKind(symbol: Symbol): SymbolDisplayPartKind {
|
||||
var flags = symbol.flags;
|
||||
|
||||
if (flags & SymbolFlags.Variable) {
|
||||
return isFirstDeclarationOfSymbolParameter(symbol) ? SymbolDisplayPartKind.parameterName : SymbolDisplayPartKind.localName;
|
||||
}
|
||||
else if (flags & SymbolFlags.Property) { return SymbolDisplayPartKind.propertyName; }
|
||||
else if (flags & SymbolFlags.GetAccessor) { return SymbolDisplayPartKind.propertyName; }
|
||||
else if (flags & SymbolFlags.SetAccessor) { return SymbolDisplayPartKind.propertyName; }
|
||||
else if (flags & SymbolFlags.EnumMember) { return SymbolDisplayPartKind.enumMemberName; }
|
||||
else if (flags & SymbolFlags.Function) { return SymbolDisplayPartKind.functionName; }
|
||||
else if (flags & SymbolFlags.Class) { return SymbolDisplayPartKind.className; }
|
||||
else if (flags & SymbolFlags.Interface) { return SymbolDisplayPartKind.interfaceName; }
|
||||
else if (flags & SymbolFlags.Enum) { return SymbolDisplayPartKind.enumName; }
|
||||
else if (flags & SymbolFlags.Module) { return SymbolDisplayPartKind.moduleName; }
|
||||
else if (flags & SymbolFlags.Method) { return SymbolDisplayPartKind.methodName; }
|
||||
else if (flags & SymbolFlags.TypeParameter) { return SymbolDisplayPartKind.typeParameterName; }
|
||||
else if (flags & SymbolFlags.TypeAlias) { return SymbolDisplayPartKind.aliasName; }
|
||||
else if (flags & SymbolFlags.Import) { return SymbolDisplayPartKind.aliasName; }
|
||||
|
||||
|
||||
return SymbolDisplayPartKind.text;
|
||||
}
|
||||
}
|
||||
|
||||
export function mapToDisplayParts(writeDisplayParts: (writer: DisplayPartsSymbolWriter) => void): SymbolDisplayPart[] {
|
||||
writeDisplayParts(displayPartWriter);
|
||||
var result = displayPartWriter.displayParts();
|
||||
displayPartWriter.clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
export function typeToDisplayParts(typechecker: TypeChecker, type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[] {
|
||||
return mapToDisplayParts(writer => {
|
||||
typechecker.getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
|
||||
});
|
||||
}
|
||||
|
||||
export function symbolToDisplayParts(typeChecker: TypeChecker, symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): SymbolDisplayPart[] {
|
||||
return mapToDisplayParts(writer => {
|
||||
typeChecker.getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags);
|
||||
});
|
||||
}
|
||||
|
||||
function signatureToDisplayParts(typechecker: TypeChecker, signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[]{
|
||||
return mapToDisplayParts(writer => {
|
||||
typechecker.getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags);
|
||||
});
|
||||
}
|
||||
|
||||
export function getDefaultCompilerOptions(): CompilerOptions {
|
||||
// Set "ScriptTarget.Latest" target by default for language service
|
||||
return {
|
||||
@@ -1509,20 +1382,6 @@ module ts {
|
||||
};
|
||||
}
|
||||
|
||||
export function compareDataObjects(dst: any, src: any): boolean {
|
||||
for (var e in dst) {
|
||||
if (typeof dst[e] === "object") {
|
||||
if (!compareDataObjects(dst[e], src[e]))
|
||||
return false;
|
||||
}
|
||||
else if (typeof dst[e] !== "function") {
|
||||
if (dst[e] !== src[e])
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export class OperationCanceledException { }
|
||||
|
||||
export class CancellationTokenObject {
|
||||
@@ -1890,20 +1749,6 @@ module ts {
|
||||
}
|
||||
|
||||
/// Helpers
|
||||
export function getNodeModifiers(node: Node): string {
|
||||
var flags = node.flags;
|
||||
var result: string[] = [];
|
||||
|
||||
if (flags & NodeFlags.Private) result.push(ScriptElementKindModifier.privateMemberModifier);
|
||||
if (flags & NodeFlags.Protected) result.push(ScriptElementKindModifier.protectedMemberModifier);
|
||||
if (flags & NodeFlags.Public) result.push(ScriptElementKindModifier.publicMemberModifier);
|
||||
if (flags & NodeFlags.Static) result.push(ScriptElementKindModifier.staticModifier);
|
||||
if (flags & NodeFlags.Export) result.push(ScriptElementKindModifier.exportedModifier);
|
||||
if (isInAmbientContext(node)) result.push(ScriptElementKindModifier.ambientModifier);
|
||||
|
||||
return result.length > 0 ? result.join(',') : ScriptElementKindModifier.none;
|
||||
}
|
||||
|
||||
function getTargetLabel(referenceNode: Node, labelName: string): Identifier {
|
||||
while (referenceNode) {
|
||||
if (referenceNode.kind === SyntaxKind.LabeledStatement && (<LabeledStatement>referenceNode).label.text === labelName) {
|
||||
@@ -2083,12 +1928,12 @@ module ts {
|
||||
var useCaseSensitivefilenames = false;
|
||||
var sourceFilesByName: Map<SourceFile> = {};
|
||||
var documentRegistry = documentRegistry;
|
||||
var cancellationToken = new CancellationTokenObject(host.getCancellationToken());
|
||||
var cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken());
|
||||
var activeCompletionSession: CompletionSession; // The current active completion session, used to get the completion entry details
|
||||
var writer: (filename: string, data: string, writeByteOrderMark: boolean) => void = undefined;
|
||||
|
||||
// Check if the localized messages json is set, otherwise query the host for it
|
||||
if (!localizedDiagnosticMessages) {
|
||||
if (!localizedDiagnosticMessages && host.getLocalizedDiagnosticMessages) {
|
||||
localizedDiagnosticMessages = host.getLocalizedDiagnosticMessages();
|
||||
}
|
||||
|
||||
@@ -2354,7 +2199,7 @@ module ts {
|
||||
};
|
||||
}
|
||||
|
||||
function getCompletionsAtPosition(filename: string, position: number, isMemberCompletion: boolean) {
|
||||
function getCompletionsAtPosition(filename: string, position: number) {
|
||||
synchronizeHostData();
|
||||
|
||||
filename = normalizeSlashes(filename);
|
||||
@@ -2429,7 +2274,7 @@ module ts {
|
||||
if (isRightOfDot) {
|
||||
// Right of dot member completion list
|
||||
var symbols: Symbol[] = [];
|
||||
isMemberCompletion = true;
|
||||
var isMemberCompletion = true;
|
||||
|
||||
if (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName || node.kind === SyntaxKind.PropertyAccessExpression) {
|
||||
var symbol = typeInfoResolver.getSymbolAtLocation(node);
|
||||
|
||||
+6
-133
@@ -88,7 +88,7 @@ module ts {
|
||||
|
||||
getSyntacticClassifications(fileName: string, start: number, length: number): string;
|
||||
|
||||
getCompletionsAtPosition(fileName: string, position: number, isMemberCompletion: boolean): string;
|
||||
getCompletionsAtPosition(fileName: string, position: number): string;
|
||||
getCompletionEntryDetails(fileName: string, position: number, entryName: string): string;
|
||||
|
||||
getQuickInfoAtPosition(fileName: string, position: number): string;
|
||||
@@ -169,131 +169,6 @@ module ts {
|
||||
getDefaultCompilationSettings(): string;
|
||||
}
|
||||
|
||||
/// TODO: delete this, it is only needed until the VS interface is updated
|
||||
export const enum LanguageVersion {
|
||||
EcmaScript3 = 0,
|
||||
EcmaScript5 = 1,
|
||||
EcmaScript6 = 2,
|
||||
}
|
||||
|
||||
export const enum ModuleGenTarget {
|
||||
Unspecified = 0,
|
||||
Synchronous = 1,
|
||||
Asynchronous = 2,
|
||||
}
|
||||
|
||||
export interface CompilationSettings {
|
||||
propagateEnumConstants?: boolean;
|
||||
removeComments?: boolean;
|
||||
watch?: boolean;
|
||||
noResolve?: boolean;
|
||||
allowAutomaticSemicolonInsertion?: boolean;
|
||||
noImplicitAny?: boolean;
|
||||
noLib?: boolean;
|
||||
codeGenTarget?: LanguageVersion;
|
||||
moduleGenTarget?: ModuleGenTarget;
|
||||
outFileOption?: string;
|
||||
outDirOption?: string;
|
||||
mapSourceFiles?: boolean;
|
||||
mapRoot?: string;
|
||||
sourceRoot?: string;
|
||||
generateDeclarationFiles?: boolean;
|
||||
useCaseSensitiveFileResolution?: boolean;
|
||||
gatherDiagnostics?: boolean;
|
||||
codepage?: number;
|
||||
emitBOM?: boolean;
|
||||
|
||||
// Declare indexer signature
|
||||
[index: string]: any;
|
||||
}
|
||||
|
||||
function languageVersionToScriptTarget(languageVersion: LanguageVersion): ScriptTarget {
|
||||
if (typeof languageVersion === "undefined") return undefined;
|
||||
|
||||
switch (languageVersion) {
|
||||
case LanguageVersion.EcmaScript3: return ScriptTarget.ES3
|
||||
case LanguageVersion.EcmaScript5: return ScriptTarget.ES5;
|
||||
case LanguageVersion.EcmaScript6: return ScriptTarget.ES6;
|
||||
default: throw Error("unsupported LanguageVersion value: " + languageVersion);
|
||||
}
|
||||
}
|
||||
|
||||
function moduleGenTargetToModuleKind(moduleGenTarget: ModuleGenTarget): ModuleKind {
|
||||
if (typeof moduleGenTarget === "undefined") return undefined;
|
||||
|
||||
switch (moduleGenTarget) {
|
||||
case ModuleGenTarget.Asynchronous: return ModuleKind.AMD;
|
||||
case ModuleGenTarget.Synchronous: return ModuleKind.CommonJS;
|
||||
case ModuleGenTarget.Unspecified: return ModuleKind.None;
|
||||
default: throw Error("unsupported ModuleGenTarget value: " + moduleGenTarget);
|
||||
}
|
||||
}
|
||||
|
||||
function scriptTargetTolanguageVersion(scriptTarget: ScriptTarget): LanguageVersion {
|
||||
if (typeof scriptTarget === "undefined") return undefined;
|
||||
|
||||
switch (scriptTarget) {
|
||||
case ScriptTarget.ES3: return LanguageVersion.EcmaScript3;
|
||||
case ScriptTarget.ES5: return LanguageVersion.EcmaScript5;
|
||||
case ScriptTarget.ES6: return LanguageVersion.EcmaScript6;
|
||||
default: throw Error("unsupported ScriptTarget value: " + scriptTarget);
|
||||
}
|
||||
}
|
||||
|
||||
function moduleKindToModuleGenTarget(moduleKind: ModuleKind): ModuleGenTarget {
|
||||
if (typeof moduleKind === "undefined") return undefined;
|
||||
|
||||
switch (moduleKind) {
|
||||
case ModuleKind.AMD: return ModuleGenTarget.Asynchronous;
|
||||
case ModuleKind.CommonJS: return ModuleGenTarget.Synchronous;
|
||||
case ModuleKind.None: return ModuleGenTarget.Unspecified;
|
||||
default: throw Error("unsupported ModuleKind value: " + moduleKind);
|
||||
}
|
||||
}
|
||||
|
||||
function compilationSettingsToCompilerOptions(settings: CompilationSettings): CompilerOptions {
|
||||
// TODO: we should not be converting, but use options all the way
|
||||
var options: CompilerOptions = {};
|
||||
//options.propagateEnumConstants = settings.propagateEnumConstants;
|
||||
options.removeComments = settings.removeComments;
|
||||
options.noResolve = settings.noResolve;
|
||||
options.noImplicitAny = settings.noImplicitAny;
|
||||
options.noLib = settings.noLib;
|
||||
options.target = languageVersionToScriptTarget(settings.codeGenTarget);
|
||||
options.module = moduleGenTargetToModuleKind(settings.moduleGenTarget);
|
||||
options.out = settings.outFileOption;
|
||||
options.outDir = settings.outDirOption;
|
||||
options.sourceMap = settings.mapSourceFiles;
|
||||
options.mapRoot = settings.mapRoot;
|
||||
options.sourceRoot = settings.sourceRoot;
|
||||
options.declaration = settings.generateDeclarationFiles;
|
||||
//options.useCaseSensitiveFileResolution = settings.useCaseSensitiveFileResolution;
|
||||
options.codepage = settings.codepage;
|
||||
options.emitBOM = settings.emitBOM;
|
||||
return options;
|
||||
}
|
||||
|
||||
function compilerOptionsToCompilationSettings(options: CompilerOptions): CompilationSettings {
|
||||
var settings: CompilationSettings = {};
|
||||
//options.propagateEnumConstants = settings.propagateEnumConstants;
|
||||
settings.removeComments = options.removeComments;
|
||||
settings.noResolve = options.noResolve;
|
||||
settings.noImplicitAny = options.noImplicitAny;
|
||||
settings.noLib = options.noLib;
|
||||
settings.codeGenTarget = scriptTargetTolanguageVersion(options.target);
|
||||
settings.moduleGenTarget = moduleKindToModuleGenTarget(options.module);
|
||||
settings.outFileOption = options.out;
|
||||
settings.outDirOption = options.outDir;
|
||||
settings.mapSourceFiles = options.sourceMap;
|
||||
settings.mapRoot = options.mapRoot;
|
||||
settings.sourceRoot = options.sourceRoot;
|
||||
settings.generateDeclarationFiles = options.declaration;
|
||||
// settings.useCaseSensitiveFileResolution = options.useCaseSensitiveFileResolution;
|
||||
settings.codepage = options.codepage;
|
||||
settings.emitBOM = options.emitBOM;
|
||||
return settings;
|
||||
}
|
||||
|
||||
function logInternalError(logger: Logger, err: Error) {
|
||||
logger.log("*INTERNAL ERROR* - Exception in typescript services: " + err.message);
|
||||
}
|
||||
@@ -355,9 +230,7 @@ module ts {
|
||||
throw Error("LanguageServiceShimHostAdapter.getCompilationSettings: empty compilationSettings");
|
||||
return null;
|
||||
}
|
||||
var options = compilationSettingsToCompilerOptions(<CompilerOptions>JSON.parse(<any>settingsJson));
|
||||
|
||||
return options;
|
||||
return <CompilerOptions>JSON.parse(settingsJson);
|
||||
}
|
||||
|
||||
public getScriptFileNames(): string[] {
|
||||
@@ -694,11 +567,11 @@ module ts {
|
||||
* to provide at the given source position and providing a member completion
|
||||
* list if requested.
|
||||
*/
|
||||
public getCompletionsAtPosition(fileName: string, position: number, isMemberCompletion: boolean) {
|
||||
public getCompletionsAtPosition(fileName: string, position: number) {
|
||||
return this.forwardJSONCall(
|
||||
"getCompletionsAtPosition('" + fileName + "', " + position + ", " + isMemberCompletion + ")",
|
||||
"getCompletionsAtPosition('" + fileName + "', " + position + ")",
|
||||
() => {
|
||||
var completion = this.languageService.getCompletionsAtPosition(fileName, position, isMemberCompletion);
|
||||
var completion = this.languageService.getCompletionsAtPosition(fileName, position);
|
||||
return completion;
|
||||
});
|
||||
}
|
||||
@@ -858,7 +731,7 @@ module ts {
|
||||
return this.forwardJSONCall(
|
||||
"getDefaultCompilationSettings()",
|
||||
() => {
|
||||
return compilerOptionsToCompilationSettings(getDefaultCompilerOptions());
|
||||
return getDefaultCompilerOptions();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
module ts {
|
||||
}
|
||||
+177
-1
@@ -270,7 +270,21 @@ module ts {
|
||||
return n.getWidth() !== 0;
|
||||
}
|
||||
|
||||
export function getTypeArgumentOrTypeParameterList(node: Node): NodeArray<Node> {
|
||||
export function getNodeModifiers(node: Node): string {
|
||||
var flags = node.flags;
|
||||
var result: string[] = [];
|
||||
|
||||
if (flags & NodeFlags.Private) result.push(ScriptElementKindModifier.privateMemberModifier);
|
||||
if (flags & NodeFlags.Protected) result.push(ScriptElementKindModifier.protectedMemberModifier);
|
||||
if (flags & NodeFlags.Public) result.push(ScriptElementKindModifier.publicMemberModifier);
|
||||
if (flags & NodeFlags.Static) result.push(ScriptElementKindModifier.staticModifier);
|
||||
if (flags & NodeFlags.Export) result.push(ScriptElementKindModifier.exportedModifier);
|
||||
if (isInAmbientContext(node)) result.push(ScriptElementKindModifier.ambientModifier);
|
||||
|
||||
return result.length > 0 ? result.join(',') : ScriptElementKindModifier.none;
|
||||
}
|
||||
|
||||
export function getTypeArgumentOrTypeParameterList(node: Node): NodeArray<Node> {
|
||||
if (node.kind === SyntaxKind.TypeReference || node.kind === SyntaxKind.CallExpression) {
|
||||
return (<CallExpression>node).typeArguments;
|
||||
}
|
||||
@@ -306,4 +320,166 @@ module ts {
|
||||
return isTemplateLiteralKind(node.kind)
|
||||
&& (node.getStart() < position && position < node.getEnd()) || (!!node.isUnterminated && position === node.getEnd());
|
||||
}
|
||||
|
||||
export function compareDataObjects(dst: any, src: any): boolean {
|
||||
for (var e in dst) {
|
||||
if (typeof dst[e] === "object") {
|
||||
if (!compareDataObjects(dst[e], src[e])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (typeof dst[e] !== "function") {
|
||||
if (dst[e] !== src[e]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Display-part writer helpers
|
||||
module ts {
|
||||
export function isFirstDeclarationOfSymbolParameter(symbol: Symbol) {
|
||||
return symbol.declarations && symbol.declarations.length > 0 && symbol.declarations[0].kind === SyntaxKind.Parameter;
|
||||
}
|
||||
|
||||
var displayPartWriter = getDisplayPartWriter();
|
||||
function getDisplayPartWriter(): DisplayPartsSymbolWriter {
|
||||
var displayParts: SymbolDisplayPart[];
|
||||
var lineStart: boolean;
|
||||
var indent: number;
|
||||
|
||||
resetWriter();
|
||||
return {
|
||||
displayParts: () => displayParts,
|
||||
writeKeyword: text => writeKind(text, SymbolDisplayPartKind.keyword),
|
||||
writeOperator: text => writeKind(text, SymbolDisplayPartKind.operator),
|
||||
writePunctuation: text => writeKind(text, SymbolDisplayPartKind.punctuation),
|
||||
writeSpace: text => writeKind(text, SymbolDisplayPartKind.space),
|
||||
writeStringLiteral: text => writeKind(text, SymbolDisplayPartKind.stringLiteral),
|
||||
writeParameter: text => writeKind(text, SymbolDisplayPartKind.parameterName),
|
||||
writeSymbol,
|
||||
writeLine,
|
||||
increaseIndent: () => { indent++; },
|
||||
decreaseIndent: () => { indent--; },
|
||||
clear: resetWriter,
|
||||
trackSymbol: () => { }
|
||||
};
|
||||
|
||||
function writeIndent() {
|
||||
if (lineStart) {
|
||||
var indentString = getIndentString(indent);
|
||||
if (indentString) {
|
||||
displayParts.push(displayPart(indentString, SymbolDisplayPartKind.space));
|
||||
}
|
||||
lineStart = false;
|
||||
}
|
||||
}
|
||||
|
||||
function writeKind(text: string, kind: SymbolDisplayPartKind) {
|
||||
writeIndent();
|
||||
displayParts.push(displayPart(text, kind));
|
||||
}
|
||||
|
||||
function writeSymbol(text: string, symbol: Symbol) {
|
||||
writeIndent();
|
||||
displayParts.push(symbolPart(text, symbol));
|
||||
}
|
||||
|
||||
function writeLine() {
|
||||
displayParts.push(lineBreakPart());
|
||||
lineStart = true;
|
||||
}
|
||||
|
||||
function resetWriter() {
|
||||
displayParts = []
|
||||
lineStart = true;
|
||||
indent = 0;
|
||||
}
|
||||
}
|
||||
|
||||
export function symbolPart(text: string, symbol: Symbol) {
|
||||
return displayPart(text, displayPartKind(symbol), symbol);
|
||||
|
||||
function displayPartKind(symbol: Symbol): SymbolDisplayPartKind {
|
||||
var flags = symbol.flags;
|
||||
|
||||
if (flags & SymbolFlags.Variable) {
|
||||
return isFirstDeclarationOfSymbolParameter(symbol) ? SymbolDisplayPartKind.parameterName : SymbolDisplayPartKind.localName;
|
||||
}
|
||||
else if (flags & SymbolFlags.Property) { return SymbolDisplayPartKind.propertyName; }
|
||||
else if (flags & SymbolFlags.GetAccessor) { return SymbolDisplayPartKind.propertyName; }
|
||||
else if (flags & SymbolFlags.SetAccessor) { return SymbolDisplayPartKind.propertyName; }
|
||||
else if (flags & SymbolFlags.EnumMember) { return SymbolDisplayPartKind.enumMemberName; }
|
||||
else if (flags & SymbolFlags.Function) { return SymbolDisplayPartKind.functionName; }
|
||||
else if (flags & SymbolFlags.Class) { return SymbolDisplayPartKind.className; }
|
||||
else if (flags & SymbolFlags.Interface) { return SymbolDisplayPartKind.interfaceName; }
|
||||
else if (flags & SymbolFlags.Enum) { return SymbolDisplayPartKind.enumName; }
|
||||
else if (flags & SymbolFlags.Module) { return SymbolDisplayPartKind.moduleName; }
|
||||
else if (flags & SymbolFlags.Method) { return SymbolDisplayPartKind.methodName; }
|
||||
else if (flags & SymbolFlags.TypeParameter) { return SymbolDisplayPartKind.typeParameterName; }
|
||||
else if (flags & SymbolFlags.TypeAlias) { return SymbolDisplayPartKind.aliasName; }
|
||||
else if (flags & SymbolFlags.Import) { return SymbolDisplayPartKind.aliasName; }
|
||||
|
||||
|
||||
return SymbolDisplayPartKind.text;
|
||||
}
|
||||
}
|
||||
|
||||
export function displayPart(text: string, kind: SymbolDisplayPartKind, symbol?: Symbol): SymbolDisplayPart {
|
||||
return <SymbolDisplayPart> {
|
||||
text: text,
|
||||
kind: SymbolDisplayPartKind[kind]
|
||||
};
|
||||
}
|
||||
|
||||
export function spacePart() {
|
||||
return displayPart(" ", SymbolDisplayPartKind.space);
|
||||
}
|
||||
|
||||
export function keywordPart(kind: SyntaxKind) {
|
||||
return displayPart(tokenToString(kind), SymbolDisplayPartKind.keyword);
|
||||
}
|
||||
|
||||
export function punctuationPart(kind: SyntaxKind) {
|
||||
return displayPart(tokenToString(kind), SymbolDisplayPartKind.punctuation);
|
||||
}
|
||||
|
||||
export function operatorPart(kind: SyntaxKind) {
|
||||
return displayPart(tokenToString(kind), SymbolDisplayPartKind.operator);
|
||||
}
|
||||
|
||||
export function textPart(text: string) {
|
||||
return displayPart(text, SymbolDisplayPartKind.text);
|
||||
}
|
||||
|
||||
export function lineBreakPart() {
|
||||
return displayPart("\n", SymbolDisplayPartKind.lineBreak);
|
||||
}
|
||||
|
||||
export function mapToDisplayParts(writeDisplayParts: (writer: DisplayPartsSymbolWriter) => void): SymbolDisplayPart[] {
|
||||
writeDisplayParts(displayPartWriter);
|
||||
var result = displayPartWriter.displayParts();
|
||||
displayPartWriter.clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
export function typeToDisplayParts(typechecker: TypeChecker, type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[] {
|
||||
return mapToDisplayParts(writer => {
|
||||
typechecker.getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
|
||||
});
|
||||
}
|
||||
|
||||
export function symbolToDisplayParts(typeChecker: TypeChecker, symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): SymbolDisplayPart[] {
|
||||
return mapToDisplayParts(writer => {
|
||||
typeChecker.getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags);
|
||||
});
|
||||
}
|
||||
|
||||
export function signatureToDisplayParts(typechecker: TypeChecker, signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[] {
|
||||
return mapToDisplayParts(writer => {
|
||||
typechecker.getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user