mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 20:33:45 -05:00
Merge branch 'master' into inlineSourceMaps
This commit is contained in:
@@ -2078,15 +2078,20 @@ module ts {
|
||||
}
|
||||
}
|
||||
else {
|
||||
// For an array binding element the specified or inferred type of the parent must be an array-like type
|
||||
if (!isArrayLikeType(parentType)) {
|
||||
error(pattern, Diagnostics.Type_0_is_not_an_array_type, typeToString(parentType));
|
||||
return unknownType;
|
||||
}
|
||||
// This elementType will be used if the specific property corresponding to this index is not
|
||||
// present (aka the tuple element property). This call also checks that the parentType is in
|
||||
// fact an iterable or array (depending on target language).
|
||||
let elementType = checkIteratedTypeOrElementType(parentType, pattern, /*allowStringInput*/ false);
|
||||
if (!declaration.dotDotDotToken) {
|
||||
if (elementType.flags & TypeFlags.Any) {
|
||||
return elementType;
|
||||
}
|
||||
|
||||
// Use specific property type when parent is a tuple or numeric index type when parent is an array
|
||||
let propName = "" + indexOf(pattern.elements, declaration);
|
||||
type = isTupleLikeType(parentType) ? getTypeOfPropertyOfType(parentType, propName) : getIndexTypeOfType(parentType, IndexKind.Number);
|
||||
type = isTupleLikeType(parentType)
|
||||
? getTypeOfPropertyOfType(parentType, propName)
|
||||
: elementType;
|
||||
if (!type) {
|
||||
if (isTupleType(parentType)) {
|
||||
error(declaration, Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, typeToString(parentType), (<TupleType>parentType).elementTypes.length, pattern.elements.length);
|
||||
@@ -2099,7 +2104,7 @@ module ts {
|
||||
}
|
||||
else {
|
||||
// Rest element has an array type with the same element type as the parent type
|
||||
type = createArrayType(getIndexTypeOfType(parentType, IndexKind.Number));
|
||||
type = createArrayType(elementType);
|
||||
}
|
||||
}
|
||||
return type;
|
||||
@@ -2188,7 +2193,34 @@ module ts {
|
||||
hasSpreadElement = true;
|
||||
}
|
||||
});
|
||||
return !elementTypes.length ? anyArrayType : hasSpreadElement ? createArrayType(getUnionType(elementTypes)) : createTupleType(elementTypes);
|
||||
if (!elementTypes.length) {
|
||||
return languageVersion >= ScriptTarget.ES6 ? createIterableType(anyType) : anyArrayType;
|
||||
}
|
||||
else if (hasSpreadElement) {
|
||||
let unionOfElements = getUnionType(elementTypes);
|
||||
if (languageVersion >= ScriptTarget.ES6) {
|
||||
// If the user has something like:
|
||||
//
|
||||
// function fun(...[a, ...b]) { }
|
||||
//
|
||||
// Normally, in ES6, the implied type of an array binding pattern with a rest element is
|
||||
// an iterable. However, there is a requirement in our type system that all rest
|
||||
// parameters be array types. To satisfy this, we have an exception to the rule that
|
||||
// says the type of an array binding pattern with a rest element is an array type
|
||||
// if it is *itself* in a rest parameter. It will still be compatible with a spreaded
|
||||
// iterable argument, but within the function it will be an array.
|
||||
let parent = pattern.parent;
|
||||
let isRestParameter = parent.kind === SyntaxKind.Parameter &&
|
||||
pattern === (<ParameterDeclaration>parent).name &&
|
||||
(<ParameterDeclaration>parent).dotDotDotToken !== undefined;
|
||||
return isRestParameter ? createArrayType(unionOfElements) : createIterableType(unionOfElements);
|
||||
}
|
||||
|
||||
return createArrayType(unionOfElements);
|
||||
}
|
||||
|
||||
// If the pattern has at least one element, and no rest element, then it should imply a tuple type.
|
||||
return createTupleType(elementTypes);
|
||||
}
|
||||
|
||||
// Return the type implied by a binding pattern. This is the type implied purely by the binding pattern itself
|
||||
@@ -3461,6 +3493,10 @@ module ts {
|
||||
return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol"));
|
||||
}
|
||||
|
||||
function createIterableType(elementType: Type): Type {
|
||||
return globalIterableType !== emptyObjectType ? createTypeReference(<GenericType>globalIterableType, [elementType]) : emptyObjectType;
|
||||
}
|
||||
|
||||
function createArrayType(elementType: Type): Type {
|
||||
// globalArrayType will be undefined if we get here during creation of the Array type. This for example happens if
|
||||
// user code augments the Array type with call or construct signatures that have an array type as the return type.
|
||||
@@ -5600,7 +5636,7 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
if (container.kind === SyntaxKind.ComputedPropertyName) {
|
||||
if (container && container.kind === SyntaxKind.ComputedPropertyName) {
|
||||
error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name);
|
||||
}
|
||||
else if (isCallExpression) {
|
||||
@@ -5968,12 +6004,14 @@ module ts {
|
||||
}
|
||||
|
||||
function checkSpreadElementExpression(node: SpreadElementExpression, contextualMapper?: TypeMapper): Type {
|
||||
let type = checkExpressionCached(node.expression, contextualMapper);
|
||||
if (!isArrayLikeType(type)) {
|
||||
error(node.expression, Diagnostics.Type_0_is_not_an_array_type, typeToString(type));
|
||||
return unknownType;
|
||||
}
|
||||
return type;
|
||||
// It is usually not safe to call checkExpressionCached if we can be contextually typing.
|
||||
// You can tell that we are contextually typing because of the contextualMapper parameter.
|
||||
// While it is true that a spread element can have a contextual type, it does not do anything
|
||||
// with this type. It is neither affected by it, nor does it propagate it to its operand.
|
||||
// So the fact that contextualMapper is passed is not important, because the operand of a spread
|
||||
// element is not contextually typed.
|
||||
let arrayOrIterableType = checkExpressionCached(node.expression, contextualMapper);
|
||||
return checkIteratedTypeOrElementType(arrayOrIterableType, node.expression, /*allowStringInput*/ false);
|
||||
}
|
||||
|
||||
function checkArrayLiteral(node: ArrayLiteralExpression, contextualMapper?: TypeMapper): Type {
|
||||
@@ -5981,18 +6019,13 @@ module ts {
|
||||
if (!elements.length) {
|
||||
return createArrayType(undefinedType);
|
||||
}
|
||||
let hasSpreadElement: boolean = false;
|
||||
let hasSpreadElement = false;
|
||||
let elementTypes: Type[] = [];
|
||||
forEach(elements, e => {
|
||||
for (let e of elements) {
|
||||
let type = checkExpression(e, contextualMapper);
|
||||
if (e.kind === SyntaxKind.SpreadElementExpression) {
|
||||
elementTypes.push(getIndexTypeOfType(type, IndexKind.Number) || anyType);
|
||||
hasSpreadElement = true;
|
||||
}
|
||||
else {
|
||||
elementTypes.push(type);
|
||||
}
|
||||
});
|
||||
elementTypes.push(type);
|
||||
hasSpreadElement = hasSpreadElement || e.kind === SyntaxKind.SpreadElementExpression;
|
||||
}
|
||||
if (!hasSpreadElement) {
|
||||
let contextualType = getContextualType(node);
|
||||
if (contextualType && contextualTypeIsTupleLikeType(contextualType) || isAssignmentTarget(node)) {
|
||||
@@ -6615,7 +6648,7 @@ module ts {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
let arg = args[i];
|
||||
if (arg.kind !== SyntaxKind.OmittedExpression) {
|
||||
let paramType = getTypeAtPosition(signature, arg.kind === SyntaxKind.SpreadElementExpression ? -1 : i);
|
||||
let paramType = getTypeAtPosition(signature, i);
|
||||
let argType: Type;
|
||||
if (i === 0 && args[i].parent.kind === SyntaxKind.TaggedTemplateExpression) {
|
||||
argType = globalTemplateStringsArrayType;
|
||||
@@ -6638,7 +6671,7 @@ module ts {
|
||||
// No need to check for omitted args and template expressions, their exlusion value is always undefined
|
||||
if (excludeArgument[i] === false) {
|
||||
let arg = args[i];
|
||||
let paramType = getTypeAtPosition(signature, arg.kind === SyntaxKind.SpreadElementExpression ? -1 : i);
|
||||
let paramType = getTypeAtPosition(signature, i);
|
||||
inferTypes(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType);
|
||||
}
|
||||
}
|
||||
@@ -6671,7 +6704,7 @@ module ts {
|
||||
let arg = args[i];
|
||||
if (arg.kind !== SyntaxKind.OmittedExpression) {
|
||||
// Check spread elements against rest type (from arity check we know spread argument corresponds to a rest parameter)
|
||||
let paramType = getTypeAtPosition(signature, arg.kind === SyntaxKind.SpreadElementExpression ? -1 : i);
|
||||
let paramType = getTypeAtPosition(signature, i);
|
||||
// A tagged template expression provides a special first argument, and string literals get string literal types
|
||||
// unless we're reporting errors
|
||||
let argType = i === 0 && node.kind === SyntaxKind.TaggedTemplateExpression ? globalTemplateStringsArrayType :
|
||||
@@ -7145,14 +7178,9 @@ module ts {
|
||||
}
|
||||
|
||||
function getTypeAtPosition(signature: Signature, pos: number): Type {
|
||||
if (pos >= 0) {
|
||||
return signature.hasRestParameter ?
|
||||
pos < signature.parameters.length - 1 ? getTypeOfSymbol(signature.parameters[pos]) : getRestTypeOfSignature(signature) :
|
||||
pos < signature.parameters.length ? getTypeOfSymbol(signature.parameters[pos]) : anyType;
|
||||
}
|
||||
return signature.hasRestParameter ?
|
||||
getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]) :
|
||||
anyArrayType;
|
||||
pos < signature.parameters.length - 1 ? getTypeOfSymbol(signature.parameters[pos]) : getRestTypeOfSignature(signature) :
|
||||
pos < signature.parameters.length ? getTypeOfSymbol(signature.parameters[pos]) : anyType;
|
||||
}
|
||||
|
||||
function assignContextualParameterTypes(signature: Signature, context: Signature, mapper: TypeMapper) {
|
||||
@@ -7588,11 +7616,10 @@ module ts {
|
||||
}
|
||||
|
||||
function checkArrayLiteralAssignment(node: ArrayLiteralExpression, sourceType: Type, contextualMapper?: TypeMapper): Type {
|
||||
// TODOO(andersh): Allow iterable source type in ES6
|
||||
if (!isArrayLikeType(sourceType)) {
|
||||
error(node, Diagnostics.Type_0_is_not_an_array_type, typeToString(sourceType));
|
||||
return sourceType;
|
||||
}
|
||||
// This elementType will be used if the specific property corresponding to this index is not
|
||||
// present (aka the tuple element property). This call also checks that the parentType is in
|
||||
// fact an iterable or array (depending on target language).
|
||||
let elementType = checkIteratedTypeOrElementType(sourceType, node, /*allowStringInput*/ false);
|
||||
let elements = node.elements;
|
||||
for (let i = 0; i < elements.length; i++) {
|
||||
let e = elements[i];
|
||||
@@ -7600,8 +7627,9 @@ module ts {
|
||||
if (e.kind !== SyntaxKind.SpreadElementExpression) {
|
||||
let propName = "" + i;
|
||||
let type = sourceType.flags & TypeFlags.Any ? sourceType :
|
||||
isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) :
|
||||
getIndexTypeOfType(sourceType, IndexKind.Number);
|
||||
isTupleLikeType(sourceType)
|
||||
? getTypeOfPropertyOfType(sourceType, propName)
|
||||
: elementType;
|
||||
if (type) {
|
||||
checkDestructuringAssignment(e, type, contextualMapper);
|
||||
}
|
||||
@@ -7616,7 +7644,7 @@ module ts {
|
||||
}
|
||||
else {
|
||||
if (i === elements.length - 1) {
|
||||
checkReferenceAssignment((<SpreadElementExpression>e).expression, sourceType, contextualMapper);
|
||||
checkReferenceAssignment((<SpreadElementExpression>e).expression, createArrayType(elementType), contextualMapper);
|
||||
}
|
||||
else {
|
||||
error(e, Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern);
|
||||
@@ -9373,29 +9401,41 @@ module ts {
|
||||
|
||||
function checkRightHandSideOfForOf(rhsExpression: Expression): Type {
|
||||
let expressionType = getTypeOfExpression(rhsExpression);
|
||||
return languageVersion >= ScriptTarget.ES6
|
||||
? checkIteratedType(expressionType, rhsExpression)
|
||||
: checkElementTypeOfArrayOrString(expressionType, rhsExpression);
|
||||
return checkIteratedTypeOrElementType(expressionType, rhsExpression, /*allowStringInput*/ true);
|
||||
}
|
||||
|
||||
function checkIteratedTypeOrElementType(inputType: Type, errorNode: Node, allowStringInput: boolean): Type {
|
||||
if (languageVersion >= ScriptTarget.ES6) {
|
||||
return checkIteratedType(inputType, errorNode) || anyType;
|
||||
}
|
||||
|
||||
if (allowStringInput) {
|
||||
return checkElementTypeOfArrayOrString(inputType, errorNode);
|
||||
}
|
||||
|
||||
if (isArrayLikeType(inputType)) {
|
||||
return getIndexTypeOfType(inputType, IndexKind.Number);
|
||||
}
|
||||
|
||||
error(errorNode, Diagnostics.Type_0_is_not_an_array_type, typeToString(inputType));
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
/**
|
||||
* When expressionForError is undefined, it means we should not report any errors.
|
||||
* When errorNode is undefined, it means we should not report any errors.
|
||||
*/
|
||||
function checkIteratedType(iterable: Type, expressionForError: Expression): Type {
|
||||
function checkIteratedType(iterable: Type, errorNode: Node): Type {
|
||||
Debug.assert(languageVersion >= ScriptTarget.ES6);
|
||||
let iteratedType = getIteratedType(iterable, expressionForError);
|
||||
let iteratedType = getIteratedType(iterable, errorNode);
|
||||
// Now even though we have extracted the iteratedType, we will have to validate that the type
|
||||
// passed in is actually an Iterable.
|
||||
if (expressionForError && iteratedType) {
|
||||
let completeIterableType = globalIterableType !== emptyObjectType
|
||||
? createTypeReference(<GenericType>globalIterableType, [iteratedType])
|
||||
: emptyObjectType;
|
||||
checkTypeAssignableTo(iterable, completeIterableType, expressionForError);
|
||||
if (errorNode && iteratedType) {
|
||||
checkTypeAssignableTo(iterable, createIterableType(iteratedType), errorNode);
|
||||
}
|
||||
|
||||
return iteratedType;
|
||||
|
||||
function getIteratedType(iterable: Type, expressionForError: Expression) {
|
||||
function getIteratedType(iterable: Type, errorNode: Node) {
|
||||
// We want to treat type as an iterable, and get the type it is an iterable of. The iterable
|
||||
// must have the following structure (annotated with the names of the variables below):
|
||||
//
|
||||
@@ -9426,6 +9466,12 @@ module ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// As an optimization, if the type is instantiated directly using the globalIterableType (Iterable<number>),
|
||||
// then just grab its type argument.
|
||||
if ((iterable.flags & TypeFlags.Reference) && (<GenericType>iterable).target === globalIterableType) {
|
||||
return (<GenericType>iterable).typeArguments[0];
|
||||
}
|
||||
|
||||
let iteratorFunction = getTypeOfPropertyOfType(iterable, getPropertyNameForKnownSymbolName("iterator"));
|
||||
if (iteratorFunction && allConstituentTypesHaveKind(iteratorFunction, TypeFlags.Any)) {
|
||||
return undefined;
|
||||
@@ -9433,8 +9479,8 @@ module ts {
|
||||
|
||||
let iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, SignatureKind.Call) : emptyArray;
|
||||
if (iteratorFunctionSignatures.length === 0) {
|
||||
if (expressionForError) {
|
||||
error(expressionForError, Diagnostics.The_right_hand_side_of_a_for_of_statement_must_have_a_Symbol_iterator_method_that_returns_an_iterator);
|
||||
if (errorNode) {
|
||||
error(errorNode, Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -9451,8 +9497,8 @@ module ts {
|
||||
|
||||
let iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, SignatureKind.Call) : emptyArray;
|
||||
if (iteratorNextFunctionSignatures.length === 0) {
|
||||
if (expressionForError) {
|
||||
error(expressionForError, Diagnostics.The_iterator_returned_by_the_right_hand_side_of_a_for_of_statement_must_have_a_next_method);
|
||||
if (errorNode) {
|
||||
error(errorNode, Diagnostics.An_iterator_must_have_a_next_method);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -9464,8 +9510,8 @@ module ts {
|
||||
|
||||
let iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value");
|
||||
if (!iteratorNextValue) {
|
||||
if (expressionForError) {
|
||||
error(expressionForError, Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property);
|
||||
if (errorNode) {
|
||||
error(errorNode, Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -9491,7 +9537,7 @@ module ts {
|
||||
* 1. Some constituent is neither a string nor an array.
|
||||
* 2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
||||
*/
|
||||
function checkElementTypeOfArrayOrString(arrayOrStringType: Type, expressionForError: Expression): Type {
|
||||
function checkElementTypeOfArrayOrString(arrayOrStringType: Type, errorNode: Node): Type {
|
||||
Debug.assert(languageVersion < ScriptTarget.ES6);
|
||||
|
||||
// After we remove all types that are StringLike, we will know if there was a string constituent
|
||||
@@ -9502,7 +9548,7 @@ module ts {
|
||||
let reportedError = false;
|
||||
if (hasStringConstituent) {
|
||||
if (languageVersion < ScriptTarget.ES5) {
|
||||
error(expressionForError, Diagnostics.Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher);
|
||||
error(errorNode, Diagnostics.Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher);
|
||||
reportedError = true;
|
||||
}
|
||||
|
||||
@@ -9522,7 +9568,7 @@ module ts {
|
||||
let diagnostic = hasStringConstituent
|
||||
? Diagnostics.Type_0_is_not_an_array_type
|
||||
: Diagnostics.Type_0_is_not_an_array_type_or_a_string_type;
|
||||
error(expressionForError, diagnostic, typeToString(arrayType));
|
||||
error(errorNode, diagnostic, typeToString(arrayType));
|
||||
}
|
||||
return hasStringConstituent ? stringType : unknownType;
|
||||
}
|
||||
|
||||
@@ -434,7 +434,7 @@ module ts {
|
||||
return path.replace(/\\/g, "/");
|
||||
}
|
||||
|
||||
// Returns length of path root (i.e. length of "/", "x:/", "//server/share/")
|
||||
// Returns length of path root (i.e. length of "/", "x:/", "//server/share/, file:///user/files")
|
||||
export function getRootLength(path: string): number {
|
||||
if (path.charCodeAt(0) === CharacterCodes.slash) {
|
||||
if (path.charCodeAt(1) !== CharacterCodes.slash) return 1;
|
||||
@@ -448,6 +448,8 @@ module ts {
|
||||
if (path.charCodeAt(2) === CharacterCodes.slash) return 3;
|
||||
return 2;
|
||||
}
|
||||
let idx = path.indexOf('://');
|
||||
if (idx !== -1) return idx + 3
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -344,8 +344,8 @@ module ts {
|
||||
The_left_hand_side_of_a_for_of_statement_cannot_be_a_previously_defined_constant: { code: 2485, category: DiagnosticCategory.Error, key: "The left-hand side of a 'for...of' statement cannot be a previously defined constant." },
|
||||
The_left_hand_side_of_a_for_in_statement_cannot_be_a_previously_defined_constant: { code: 2486, category: DiagnosticCategory.Error, key: "The left-hand side of a 'for...in' statement cannot be a previously defined constant." },
|
||||
Invalid_left_hand_side_in_for_of_statement: { code: 2487, category: DiagnosticCategory.Error, key: "Invalid left-hand side in 'for...of' statement." },
|
||||
The_right_hand_side_of_a_for_of_statement_must_have_a_Symbol_iterator_method_that_returns_an_iterator: { code: 2488, category: DiagnosticCategory.Error, key: "The right-hand side of a 'for...of' statement must have a '[Symbol.iterator]()' method that returns an iterator." },
|
||||
The_iterator_returned_by_the_right_hand_side_of_a_for_of_statement_must_have_a_next_method: { code: 2489, category: DiagnosticCategory.Error, key: "The iterator returned by the right-hand side of a 'for...of' statement must have a 'next()' method." },
|
||||
Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator: { code: 2488, category: DiagnosticCategory.Error, key: "Type must have a '[Symbol.iterator]()' method that returns an iterator." },
|
||||
An_iterator_must_have_a_next_method: { code: 2489, category: DiagnosticCategory.Error, key: "An iterator must have a 'next()' method." },
|
||||
The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property: { code: 2490, category: DiagnosticCategory.Error, key: "The type returned by the 'next()' method of an iterator must have a 'value' property." },
|
||||
The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern: { code: 2491, category: DiagnosticCategory.Error, key: "The left-hand side of a 'for...in' statement cannot be a destructuring pattern." },
|
||||
Cannot_redeclare_identifier_0_in_catch_clause: { code: 2492, category: DiagnosticCategory.Error, key: "Cannot redeclare identifier '{0}' in catch clause" },
|
||||
|
||||
@@ -1367,11 +1367,11 @@
|
||||
"category": "Error",
|
||||
"code": 2487
|
||||
},
|
||||
"The right-hand side of a 'for...of' statement must have a '[Symbol.iterator]()' method that returns an iterator.": {
|
||||
"Type must have a '[Symbol.iterator]()' method that returns an iterator.": {
|
||||
"category": "Error",
|
||||
"code": 2488
|
||||
},
|
||||
"The iterator returned by the right-hand side of a 'for...of' statement must have a 'next()' method.": {
|
||||
"An iterator must have a 'next()' method.": {
|
||||
"category": "Error",
|
||||
"code": 2489
|
||||
},
|
||||
|
||||
@@ -1157,8 +1157,8 @@ var __param = this.__param || function(index, decorator) { return function (targ
|
||||
if (!computedPropertyNamesToGeneratedNames) {
|
||||
computedPropertyNamesToGeneratedNames = [];
|
||||
}
|
||||
|
||||
let generatedName = computedPropertyNamesToGeneratedNames[node.id];
|
||||
|
||||
let generatedName = computedPropertyNamesToGeneratedNames[getNodeId(node)];
|
||||
if (generatedName) {
|
||||
// we have already generated a variable for this node, write that value instead.
|
||||
write(generatedName);
|
||||
@@ -1166,7 +1166,7 @@ var __param = this.__param || function(index, decorator) { return function (targ
|
||||
}
|
||||
|
||||
generatedName = createAndRecordTempVariable(TempFlags.Auto).text;
|
||||
computedPropertyNamesToGeneratedNames[node.id] = generatedName;
|
||||
computedPropertyNamesToGeneratedNames[getNodeId(node)] = generatedName;
|
||||
write(generatedName);
|
||||
write(" = ");
|
||||
}
|
||||
@@ -1402,211 +1402,163 @@ var __param = this.__param || function(index, decorator) { return function (targ
|
||||
}
|
||||
}
|
||||
|
||||
function emitDownlevelObjectLiteralWithComputedProperties(node: ObjectLiteralExpression, firstComputedPropertyIndex: number): void {
|
||||
let parenthesizedObjectLiteral = createDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex);
|
||||
return emit(parenthesizedObjectLiteral);
|
||||
function emitObjectLiteralBody(node: ObjectLiteralExpression, numElements: number): void {
|
||||
if (numElements === 0) {
|
||||
write("{}");
|
||||
return;
|
||||
}
|
||||
|
||||
write("{");
|
||||
|
||||
if (numElements > 0) {
|
||||
var properties = node.properties;
|
||||
|
||||
// If we are not doing a downlevel transformation for object literals,
|
||||
// then try to preserve the original shape of the object literal.
|
||||
// Otherwise just try to preserve the formatting.
|
||||
if (numElements === properties.length) {
|
||||
emitLinePreservingList(node, properties, /* allowTrailingComma */ languageVersion >= ScriptTarget.ES5, /* spacesBetweenBraces */ true);
|
||||
}
|
||||
else {
|
||||
let multiLine = (node.flags & NodeFlags.MultiLine) !== 0;
|
||||
if (!multiLine) {
|
||||
write(" ");
|
||||
}
|
||||
else {
|
||||
increaseIndent();
|
||||
}
|
||||
|
||||
emitList(properties, 0, numElements, /*multiLine*/ multiLine, /*trailingComma*/ false);
|
||||
|
||||
if (!multiLine) {
|
||||
write(" ");
|
||||
}
|
||||
else {
|
||||
decreaseIndent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
write("}");
|
||||
}
|
||||
|
||||
function createDownlevelObjectLiteralWithComputedProperties(originalObjectLiteral: ObjectLiteralExpression, firstComputedPropertyIndex: number): ParenthesizedExpression {
|
||||
function emitDownlevelObjectLiteralWithComputedProperties(node: ObjectLiteralExpression, firstComputedPropertyIndex: number) {
|
||||
let multiLine = (node.flags & NodeFlags.MultiLine) !== 0;
|
||||
let properties = node.properties;
|
||||
|
||||
write("(");
|
||||
|
||||
if (multiLine) {
|
||||
increaseIndent();
|
||||
}
|
||||
|
||||
// For computed properties, we need to create a unique handle to the object
|
||||
// literal so we can modify it without risking internal assignments tainting the object.
|
||||
let tempVar = createAndRecordTempVariable(TempFlags.Auto);
|
||||
|
||||
// Hold onto the initial non-computed properties in a new object literal,
|
||||
// then create the rest through property accesses on the temp variable.
|
||||
let initialObjectLiteral = <ObjectLiteralExpression>createSynthesizedNode(SyntaxKind.ObjectLiteralExpression);
|
||||
initialObjectLiteral.properties = <NodeArray<ObjectLiteralElement>>originalObjectLiteral.properties.slice(0, firstComputedPropertyIndex);
|
||||
initialObjectLiteral.flags |= NodeFlags.MultiLine;
|
||||
// Write out the first non-computed properties
|
||||
// (or all properties if none of them are computed),
|
||||
// then emit the rest through indexing on the temp variable.
|
||||
emit(tempVar)
|
||||
write(" = ");
|
||||
emitObjectLiteralBody(node, firstComputedPropertyIndex);
|
||||
|
||||
// The comma expressions that will patch the object literal.
|
||||
// This will end up being something like '_a = { ... }, _a.x = 10, _a.y = 20, _a'.
|
||||
let propertyPatches = createBinaryExpression(tempVar, SyntaxKind.EqualsToken, initialObjectLiteral);
|
||||
for (let i = firstComputedPropertyIndex, n = properties.length; i < n; i++) {
|
||||
writeComma();
|
||||
|
||||
ts.forEach(originalObjectLiteral.properties, property => {
|
||||
let patchedProperty = tryCreatePatchingPropertyAssignment(originalObjectLiteral, tempVar, property);
|
||||
if (patchedProperty) {
|
||||
// TODO(drosen): Preserve comments
|
||||
//let leadingComments = getLeadingCommentRanges(currentSourceFile.text, property.pos);
|
||||
//let trailingComments = getTrailingCommentRanges(currentSourceFile.text, property.end);
|
||||
//addCommentsToSynthesizedNode(patchedProperty, leadingComments, trailingComments);
|
||||
let property = properties[i];
|
||||
|
||||
propertyPatches = createBinaryExpression(propertyPatches, SyntaxKind.CommaToken, patchedProperty);
|
||||
emitStart(property)
|
||||
if (property.kind === SyntaxKind.GetAccessor || property.kind === SyntaxKind.SetAccessor) {
|
||||
// TODO (drosen): Reconcile with 'emitMemberFunctions'.
|
||||
let accessors = getAllAccessorDeclarations(node.properties, <AccessorDeclaration>property);
|
||||
if (property !== accessors.firstAccessor) {
|
||||
continue;
|
||||
}
|
||||
write("Object.defineProperty(");
|
||||
emit(tempVar);
|
||||
write(", ");
|
||||
emitStart(node.name);
|
||||
emitExpressionForPropertyName(property.name);
|
||||
emitEnd(property.name);
|
||||
write(", {");
|
||||
increaseIndent();
|
||||
if (accessors.getAccessor) {
|
||||
writeLine()
|
||||
emitLeadingComments(accessors.getAccessor);
|
||||
write("get: ");
|
||||
emitStart(accessors.getAccessor);
|
||||
write("function ");
|
||||
emitSignatureAndBody(accessors.getAccessor);
|
||||
emitEnd(accessors.getAccessor);
|
||||
emitTrailingComments(accessors.getAccessor);
|
||||
write(",");
|
||||
}
|
||||
if (accessors.setAccessor) {
|
||||
writeLine();
|
||||
emitLeadingComments(accessors.setAccessor);
|
||||
write("set: ");
|
||||
emitStart(accessors.setAccessor);
|
||||
write("function ");
|
||||
emitSignatureAndBody(accessors.setAccessor);
|
||||
emitEnd(accessors.setAccessor);
|
||||
emitTrailingComments(accessors.setAccessor);
|
||||
write(",");
|
||||
}
|
||||
writeLine();
|
||||
write("enumerable: true,");
|
||||
writeLine();
|
||||
write("configurable: true");
|
||||
decreaseIndent();
|
||||
writeLine();
|
||||
write("})");
|
||||
emitEnd(property);
|
||||
}
|
||||
});
|
||||
else {
|
||||
emitLeadingComments(property);
|
||||
emitStart(property.name);
|
||||
emit(tempVar);
|
||||
emitMemberAccessForPropertyName(property.name);
|
||||
emitEnd(property.name);
|
||||
|
||||
// Finally, return the temp variable.
|
||||
propertyPatches = createBinaryExpression(propertyPatches, SyntaxKind.CommaToken, createIdentifier(tempVar.text, /*startsOnNewLine:*/ true));
|
||||
write(" = ");
|
||||
|
||||
let result = createParenthesizedExpression(propertyPatches);
|
||||
|
||||
// TODO(drosen): Preserve comments
|
||||
// let leadingComments = getLeadingCommentRanges(currentSourceFile.text, originalObjectLiteral.pos);
|
||||
// let trailingComments = getTrailingCommentRanges(currentSourceFile.text, originalObjectLiteral.end);
|
||||
//addCommentsToSynthesizedNode(result, leadingComments, trailingComments);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function addCommentsToSynthesizedNode(node: SynthesizedNode, leadingCommentRanges: CommentRange[], trailingCommentRanges: CommentRange[]): void {
|
||||
node.leadingCommentRanges = leadingCommentRanges;
|
||||
node.trailingCommentRanges = trailingCommentRanges;
|
||||
}
|
||||
|
||||
// Returns 'undefined' if a property has already been accounted for
|
||||
// (e.g. a 'get' accessor which has already been emitted along with its 'set' accessor).
|
||||
function tryCreatePatchingPropertyAssignment(objectLiteral: ObjectLiteralExpression, tempVar: Identifier, property: ObjectLiteralElement): Expression {
|
||||
let leftHandSide = createMemberAccessForPropertyName(tempVar, property.name);
|
||||
let maybeRightHandSide = tryGetRightHandSideOfPatchingPropertyAssignment(objectLiteral, property);
|
||||
|
||||
return maybeRightHandSide && createBinaryExpression(leftHandSide, SyntaxKind.EqualsToken, maybeRightHandSide, /*startsOnNewLine:*/ true);
|
||||
}
|
||||
|
||||
function tryGetRightHandSideOfPatchingPropertyAssignment(objectLiteral: ObjectLiteralExpression, property: ObjectLiteralElement) {
|
||||
switch (property.kind) {
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
return (<PropertyAssignment>property).initializer;
|
||||
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
// TODO: (andersh) Technically it isn't correct to make an identifier here since getExpressionNamePrefix returns
|
||||
// a string containing a dotted name. In general I'm not a fan of mini tree rewriters as this one, elsewhere we
|
||||
// manage by just emitting strings (which is a lot more performant).
|
||||
//let prefix = createIdentifier(resolver.getExpressionNamePrefix((<ShorthandPropertyAssignment>property).name));
|
||||
//return createPropertyAccessExpression(prefix, (<ShorthandPropertyAssignment>property).name);
|
||||
return createIdentifier(resolver.getExpressionNameSubstitution((<ShorthandPropertyAssignment>property).name, getGeneratedNameForNode));
|
||||
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
return createFunctionExpression((<MethodDeclaration>property).parameters, (<MethodDeclaration>property).body);
|
||||
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
let { firstAccessor, getAccessor, setAccessor } = getAllAccessorDeclarations(objectLiteral.properties, <AccessorDeclaration>property);
|
||||
|
||||
// Only emit the first accessor.
|
||||
if (firstAccessor !== property) {
|
||||
return undefined;
|
||||
if (property.kind === SyntaxKind.PropertyAssignment) {
|
||||
emit((<PropertyAssignment>property).initializer);
|
||||
}
|
||||
|
||||
let propertyDescriptor = <ObjectLiteralExpression>createSynthesizedNode(SyntaxKind.ObjectLiteralExpression);
|
||||
|
||||
let descriptorProperties = <NodeArray<ObjectLiteralElement>>[];
|
||||
if (getAccessor) {
|
||||
let getProperty = createPropertyAssignment(createIdentifier("get"), createFunctionExpression(getAccessor.parameters, getAccessor.body));
|
||||
descriptorProperties.push(getProperty);
|
||||
else if (property.kind === SyntaxKind.ShorthandPropertyAssignment) {
|
||||
emitExpressionIdentifier((<ShorthandPropertyAssignment>property).name);
|
||||
}
|
||||
if (setAccessor) {
|
||||
let setProperty = createPropertyAssignment(createIdentifier("set"), createFunctionExpression(setAccessor.parameters, setAccessor.body));
|
||||
descriptorProperties.push(setProperty);
|
||||
else if (property.kind === SyntaxKind.MethodDeclaration) {
|
||||
emitFunctionDeclaration(<MethodDeclaration>property);
|
||||
}
|
||||
else {
|
||||
Debug.fail("ObjectLiteralElement type not accounted for: " + property.kind);
|
||||
}
|
||||
}
|
||||
|
||||
let trueExpr = <PrimaryExpression>createSynthesizedNode(SyntaxKind.TrueKeyword);
|
||||
|
||||
let enumerableTrue = createPropertyAssignment(createIdentifier("enumerable"), trueExpr);
|
||||
descriptorProperties.push(enumerableTrue);
|
||||
|
||||
let configurableTrue = createPropertyAssignment(createIdentifier("configurable"), trueExpr);
|
||||
descriptorProperties.push(configurableTrue);
|
||||
|
||||
propertyDescriptor.properties = descriptorProperties;
|
||||
|
||||
let objectDotDefineProperty = createPropertyAccessExpression(createIdentifier("Object"), createIdentifier("defineProperty"));
|
||||
return createCallExpression(objectDotDefineProperty, createNodeArray(propertyDescriptor));
|
||||
|
||||
default:
|
||||
Debug.fail(`ObjectLiteralElement kind ${property.kind} not accounted for.`);
|
||||
emitEnd(property);
|
||||
}
|
||||
}
|
||||
|
||||
function createParenthesizedExpression(expression: Expression) {
|
||||
let result = <ParenthesizedExpression>createSynthesizedNode(SyntaxKind.ParenthesizedExpression);
|
||||
result.expression = expression;
|
||||
writeComma();
|
||||
emit(tempVar);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function createNodeArray<T extends Node>(...elements: T[]): NodeArray<T> {
|
||||
let result = <NodeArray<T>>elements;
|
||||
result.pos = -1;
|
||||
result.end = -1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function createBinaryExpression(left: Expression, operator: SyntaxKind, right: Expression, startsOnNewLine?: boolean): BinaryExpression {
|
||||
let result = <BinaryExpression>createSynthesizedNode(SyntaxKind.BinaryExpression, startsOnNewLine);
|
||||
result.operatorToken = createSynthesizedNode(operator);
|
||||
result.left = left;
|
||||
result.right = right;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function createExpressionStatement(expression: Expression): ExpressionStatement {
|
||||
let result = <ExpressionStatement>createSynthesizedNode(SyntaxKind.ExpressionStatement);
|
||||
result.expression = expression;
|
||||
return result;
|
||||
}
|
||||
|
||||
function createMemberAccessForPropertyName(expression: LeftHandSideExpression, memberName: DeclarationName): PropertyAccessExpression | ElementAccessExpression {
|
||||
if (memberName.kind === SyntaxKind.Identifier) {
|
||||
return createPropertyAccessExpression(expression, <Identifier>memberName);
|
||||
if (multiLine) {
|
||||
decreaseIndent();
|
||||
writeLine();
|
||||
}
|
||||
else if (memberName.kind === SyntaxKind.StringLiteral || memberName.kind === SyntaxKind.NumericLiteral) {
|
||||
return createElementAccessExpression(expression, <LiteralExpression>memberName);
|
||||
|
||||
write(")");
|
||||
|
||||
function writeComma() {
|
||||
if (multiLine) {
|
||||
write(",");
|
||||
writeLine();
|
||||
}
|
||||
else {
|
||||
write(", ");
|
||||
}
|
||||
}
|
||||
else if (memberName.kind === SyntaxKind.ComputedPropertyName) {
|
||||
return createElementAccessExpression(expression, (<ComputedPropertyName>memberName).expression);
|
||||
}
|
||||
else {
|
||||
Debug.fail(`Kind '${memberName.kind}' not accounted for.`);
|
||||
}
|
||||
}
|
||||
|
||||
function createPropertyAssignment(name: LiteralExpression | Identifier, initializer: Expression) {
|
||||
let result = <PropertyAssignment>createSynthesizedNode(SyntaxKind.PropertyAssignment);
|
||||
result.name = name;
|
||||
result.initializer = initializer;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function createFunctionExpression(parameters: NodeArray<ParameterDeclaration>, body: Block): FunctionExpression {
|
||||
let result = <FunctionExpression>createSynthesizedNode(SyntaxKind.FunctionExpression);
|
||||
result.parameters = parameters;
|
||||
result.body = body;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function createPropertyAccessExpression(expression: LeftHandSideExpression, name: Identifier): PropertyAccessExpression {
|
||||
let result = <PropertyAccessExpression>createSynthesizedNode(SyntaxKind.PropertyAccessExpression);
|
||||
result.expression = expression;
|
||||
result.dotToken = createSynthesizedNode(SyntaxKind.DotToken);
|
||||
result.name = name;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function createElementAccessExpression(expression: LeftHandSideExpression, argumentExpression: Expression): ElementAccessExpression {
|
||||
let result = <ElementAccessExpression>createSynthesizedNode(SyntaxKind.ElementAccessExpression);
|
||||
result.expression = expression;
|
||||
result.argumentExpression = argumentExpression;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function createIdentifier(name: string, startsOnNewLine?: boolean) {
|
||||
let result = <Identifier>createSynthesizedNode(SyntaxKind.Identifier, startsOnNewLine);
|
||||
result.text = name;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function createCallExpression(invokedExpression: MemberExpression, arguments: NodeArray<Expression>) {
|
||||
let result = <CallExpression>createSynthesizedNode(SyntaxKind.CallExpression);
|
||||
result.expression = invokedExpression;
|
||||
result.arguments = arguments;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function emitObjectLiteral(node: ObjectLiteralExpression): void {
|
||||
@@ -1634,13 +1586,33 @@ var __param = this.__param || function(index, decorator) { return function (targ
|
||||
|
||||
// Ordinary case: either the object has no computed properties
|
||||
// or we're compiling with an ES6+ target.
|
||||
write("{");
|
||||
emitObjectLiteralBody(node, properties.length);
|
||||
}
|
||||
|
||||
if (properties.length) {
|
||||
emitLinePreservingList(node, properties, /*allowTrailingComma:*/ languageVersion >= ScriptTarget.ES5, /*spacesBetweenBraces:*/ true)
|
||||
}
|
||||
function createBinaryExpression(left: Expression, operator: SyntaxKind, right: Expression, startsOnNewLine?: boolean): BinaryExpression {
|
||||
let result = <BinaryExpression>createSynthesizedNode(SyntaxKind.BinaryExpression, startsOnNewLine);
|
||||
result.operatorToken = createSynthesizedNode(operator);
|
||||
result.left = left;
|
||||
result.right = right;
|
||||
|
||||
write("}");
|
||||
return result;
|
||||
}
|
||||
|
||||
function createPropertyAccessExpression(expression: LeftHandSideExpression, name: Identifier): PropertyAccessExpression {
|
||||
let result = <PropertyAccessExpression>createSynthesizedNode(SyntaxKind.PropertyAccessExpression);
|
||||
result.expression = expression;
|
||||
result.dotToken = createSynthesizedNode(SyntaxKind.DotToken);
|
||||
result.name = name;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function createElementAccessExpression(expression: LeftHandSideExpression, argumentExpression: Expression): ElementAccessExpression {
|
||||
let result = <ElementAccessExpression>createSynthesizedNode(SyntaxKind.ElementAccessExpression);
|
||||
result.expression = expression;
|
||||
result.argumentExpression = argumentExpression;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function emitComputedPropertyName(node: ComputedPropertyName) {
|
||||
|
||||
@@ -526,6 +526,19 @@ module ts {
|
||||
// the *body* of the container.
|
||||
node = node.parent;
|
||||
break;
|
||||
case SyntaxKind.Decorator:
|
||||
// Decorators are always applied outside of the body of a class or method.
|
||||
if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) {
|
||||
// If the decorator's parent is a Parameter, we resolve the this container from
|
||||
// the grandparent class declaration.
|
||||
node = node.parent.parent;
|
||||
}
|
||||
else if (isClassElement(node.parent)) {
|
||||
// If the decorator's parent is a class element, we resolve the 'this' container
|
||||
// from the parent class declaration.
|
||||
node = node.parent;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.ArrowFunction:
|
||||
if (!includeArrowFunctions) {
|
||||
continue;
|
||||
@@ -568,6 +581,19 @@ module ts {
|
||||
// the *body* of the container.
|
||||
node = node.parent;
|
||||
break;
|
||||
case SyntaxKind.Decorator:
|
||||
// Decorators are always applied outside of the body of a class or method.
|
||||
if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) {
|
||||
// If the decorator's parent is a Parameter, we resolve the this container from
|
||||
// the grandparent class declaration.
|
||||
node = node.parent.parent;
|
||||
}
|
||||
else if (isClassElement(node.parent)) {
|
||||
// If the decorator's parent is a class element, we resolve the 'this' container
|
||||
// from the parent class declaration.
|
||||
node = node.parent;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
@@ -754,6 +780,8 @@ module ts {
|
||||
return node === (<TemplateSpan>parent).expression;
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
return node === (<ComputedPropertyName>parent).expression;
|
||||
case SyntaxKind.Decorator:
|
||||
return true;
|
||||
default:
|
||||
if (isExpression(parent)) {
|
||||
return true;
|
||||
@@ -919,6 +947,7 @@ module ts {
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.IndexSignature:
|
||||
return true;
|
||||
default:
|
||||
|
||||
@@ -336,6 +336,9 @@ module Harness.LanguageService {
|
||||
getOccurrencesAtPosition(fileName: string, position: number): ts.ReferenceEntry[] {
|
||||
return unwrapJSONCallResult(this.shim.getOccurrencesAtPosition(fileName, position));
|
||||
}
|
||||
getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): ts.DocumentHighlights[] {
|
||||
return unwrapJSONCallResult(this.shim.getDocumentHighlights(fileName, position, JSON.stringify(filesToSearch)));
|
||||
}
|
||||
getNavigateToItems(searchValue: string): ts.NavigateToItem[] {
|
||||
return unwrapJSONCallResult(this.shim.getNavigateToItems(searchValue));
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ class TypeWriterWalker {
|
||||
case ts.SyntaxKind.PostfixUnaryExpression:
|
||||
case ts.SyntaxKind.BinaryExpression:
|
||||
case ts.SyntaxKind.ConditionalExpression:
|
||||
case ts.SyntaxKind.SpreadElementExpression:
|
||||
this.log(node, this.getTypeOfNode(node));
|
||||
break;
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ module ts.server {
|
||||
var response: T = JSON.parse(responseBody);
|
||||
}
|
||||
catch (e) {
|
||||
throw new Error("Malformed response: Failed to parse server response: " + lastMessage + ". \r\n Error detailes: " + e.message);
|
||||
throw new Error("Malformed response: Failed to parse server response: " + lastMessage + ". \r\n Error details: " + e.message);
|
||||
}
|
||||
|
||||
// verify the sequence numbers
|
||||
@@ -446,6 +446,7 @@ module ts.server {
|
||||
if (!response.body) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var helpItems: protocol.SignatureHelpItems = response.body;
|
||||
var span = helpItems.applicableSpan;
|
||||
var start = this.lineOffsetToPosition(fileName, span.start);
|
||||
@@ -465,6 +466,29 @@ module ts.server {
|
||||
}
|
||||
|
||||
getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[] {
|
||||
var lineOffset = this.positionToOneBasedLineOffset(fileName, position);
|
||||
var args: protocol.FileLocationRequestArgs = {
|
||||
file: fileName,
|
||||
line: lineOffset.line,
|
||||
offset: lineOffset.offset,
|
||||
};
|
||||
|
||||
var request = this.processRequest<protocol.OccurrencesRequest>(CommandNames.Occurrences, args);
|
||||
var response = this.processResponse<protocol.OccurrencesResponse>(request);
|
||||
|
||||
return response.body.map(entry => {
|
||||
var fileName = entry.file;
|
||||
var start = this.lineOffsetToPosition(fileName, entry.start);
|
||||
var end = this.lineOffsetToPosition(fileName, entry.end);
|
||||
return {
|
||||
fileName,
|
||||
textSpan: ts.createTextSpanFromBounds(start, end),
|
||||
isWriteAccess: entry.isWriteAccess,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
getDocumentHighlights(fileName: string, position: number): DocumentHighlights[] {
|
||||
throw new Error("Not Implemented Yet.");
|
||||
}
|
||||
|
||||
|
||||
@@ -458,7 +458,7 @@ module ts.server {
|
||||
var info = this.filenameToScriptInfo[args.file];
|
||||
if (info) {
|
||||
info.setFormatOptions(args.formatOptions);
|
||||
this.log("Host configuration update for file " + args.file);
|
||||
this.log("Host configuration update for file " + args.file, "Info");
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -823,7 +823,6 @@ module ts.server {
|
||||
*/
|
||||
|
||||
closeClientFile(filename: string) {
|
||||
// TODO: tsconfig check
|
||||
var info = ts.lookUp(this.filenameToScriptInfo, filename);
|
||||
if (info) {
|
||||
this.closeOpenFile(info);
|
||||
@@ -856,6 +855,9 @@ module ts.server {
|
||||
}
|
||||
|
||||
printProjects() {
|
||||
if (!this.psLogger.isVerbose()) {
|
||||
return;
|
||||
}
|
||||
this.psLogger.startGroup();
|
||||
for (var i = 0, len = this.inferredProjects.length; i < len; i++) {
|
||||
var project = this.inferredProjects[i];
|
||||
|
||||
26
src/server/protocol.d.ts
vendored
26
src/server/protocol.d.ts
vendored
@@ -165,6 +165,25 @@ declare module ts.server.protocol {
|
||||
body?: FileSpan[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get occurrences request; value of command field is
|
||||
* "occurrences". Return response giving spans that are relevant
|
||||
* in the file at a given line and column.
|
||||
*/
|
||||
export interface OccurrencesRequest extends FileLocationRequest {
|
||||
}
|
||||
|
||||
export interface OccurrencesResponseItem extends FileSpan {
|
||||
/**
|
||||
* True if the occurrence is a write location, false otherwise.
|
||||
*/
|
||||
isWriteAccess: boolean;
|
||||
}
|
||||
|
||||
export interface OccurrencesResponse extends Response {
|
||||
body?: OccurrencesResponseItem[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Find references request; value of command field is
|
||||
* "references". Return response giving the file locations that
|
||||
@@ -405,6 +424,13 @@ declare module ts.server.protocol {
|
||||
arguments: OpenRequestArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit request; value of command field is "exit". Ask the server process
|
||||
* to exit.
|
||||
*/
|
||||
export interface ExitRequest extends Request {
|
||||
}
|
||||
|
||||
/**
|
||||
* Close request; value of command field is "close". Notify the
|
||||
* server that the client has closed a previously open file. If
|
||||
|
||||
@@ -177,6 +177,12 @@ module ts.server {
|
||||
super(host, logger);
|
||||
}
|
||||
|
||||
exit() {
|
||||
this.projectService.log("Exiting...","Info");
|
||||
this.projectService.closeLog();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
listen() {
|
||||
rl.on('line',(input: string) => {
|
||||
var message = input.trim();
|
||||
@@ -184,9 +190,7 @@ module ts.server {
|
||||
});
|
||||
|
||||
rl.on('close',() => {
|
||||
this.projectService.log("Exiting...");
|
||||
this.projectService.closeLog();
|
||||
process.exit(0);
|
||||
this.exit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,25 +76,27 @@ module ts.server {
|
||||
}
|
||||
|
||||
export module CommandNames {
|
||||
export var Brace = "brace";
|
||||
export var Change = "change";
|
||||
export var Close = "close";
|
||||
export var Completions = "completions";
|
||||
export var CompletionDetails = "completionEntryDetails";
|
||||
export var SignatureHelp = "signatureHelp";
|
||||
export var Configure = "configure";
|
||||
export var Definition = "definition";
|
||||
export var Exit = "exit";
|
||||
export var Format = "format";
|
||||
export var Formatonkey = "formatonkey";
|
||||
export var Geterr = "geterr";
|
||||
export var NavBar = "navbar";
|
||||
export var Navto = "navto";
|
||||
export var Occurrences = "occurrences";
|
||||
export var Open = "open";
|
||||
export var Quickinfo = "quickinfo";
|
||||
export var References = "references";
|
||||
export var Reload = "reload";
|
||||
export var Rename = "rename";
|
||||
export var Saveto = "saveto";
|
||||
export var Brace = "brace";
|
||||
export var SignatureHelp = "signatureHelp";
|
||||
export var Unknown = "unknown";
|
||||
}
|
||||
|
||||
@@ -116,7 +118,7 @@ module ts.server {
|
||||
|
||||
constructor(private host: ServerHost, private logger: Logger) {
|
||||
this.projectService =
|
||||
new ProjectService(host, logger, (eventName,project,fileName) => {
|
||||
new ProjectService(host, logger, (eventName, project, fileName) => {
|
||||
this.handleEvent(eventName, project, fileName);
|
||||
});
|
||||
}
|
||||
@@ -261,7 +263,7 @@ module ts.server {
|
||||
}
|
||||
}
|
||||
|
||||
getDefinition(line: number, offset: number, fileName: string): protocol.FileSpan[] {
|
||||
getDefinition({ line, offset, file: fileName }: protocol.FileLocationRequestArgs): protocol.FileSpan[] {
|
||||
var file = ts.normalizePath(fileName);
|
||||
var project = this.projectService.getProjectForFile(file);
|
||||
if (!project) {
|
||||
@@ -283,7 +285,37 @@ module ts.server {
|
||||
}));
|
||||
}
|
||||
|
||||
getRenameLocations(line: number, offset: number, fileName: string,findInComments: boolean, findInStrings: boolean): protocol.RenameResponseBody {
|
||||
getOccurrences({ line, offset, file: fileName }: protocol.FileLocationRequestArgs): protocol.OccurrencesResponseItem[] {
|
||||
fileName = ts.normalizePath(fileName);
|
||||
let project = this.projectService.getProjectForFile(fileName);
|
||||
|
||||
if (!project) {
|
||||
throw Errors.NoProject;
|
||||
}
|
||||
|
||||
let { compilerService } = project;
|
||||
let position = compilerService.host.lineOffsetToPosition(fileName, line, offset);
|
||||
|
||||
let occurrences = compilerService.languageService.getOccurrencesAtPosition(fileName, position);
|
||||
|
||||
if (!occurrences) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return occurrences.map(occurrence => {
|
||||
let { fileName, isWriteAccess, textSpan } = occurrence;
|
||||
let start = compilerService.host.positionToLineOffset(fileName, textSpan.start);
|
||||
let end = compilerService.host.positionToLineOffset(fileName, ts.textSpanEnd(textSpan));
|
||||
return {
|
||||
start,
|
||||
end,
|
||||
file: fileName,
|
||||
isWriteAccess
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getRenameLocations({line, offset, file: fileName, findInComments, findInStrings }: protocol.RenameRequestArgs): protocol.RenameResponseBody {
|
||||
var file = ts.normalizePath(fileName);
|
||||
var project = this.projectService.getProjectForFile(file);
|
||||
if (!project) {
|
||||
@@ -351,7 +383,7 @@ module ts.server {
|
||||
return { info: renameInfo, locs: bakedRenameLocs };
|
||||
}
|
||||
|
||||
getReferences(line: number, offset: number, fileName: string): protocol.ReferencesResponseBody {
|
||||
getReferences({ line, offset, file: fileName }: protocol.FileLocationRequestArgs): protocol.ReferencesResponseBody {
|
||||
// TODO: get all projects for this file; report refs for all projects deleting duplicates
|
||||
// can avoid duplicates by eliminating same ref file from subsequent projects
|
||||
var file = ts.normalizePath(fileName);
|
||||
@@ -377,7 +409,7 @@ module ts.server {
|
||||
var nameSpan = nameInfo.textSpan;
|
||||
var nameColStart = compilerService.host.positionToLineOffset(file, nameSpan.start).offset;
|
||||
var nameText = compilerService.host.getScriptSnapshot(file).getText(nameSpan.start, ts.textSpanEnd(nameSpan));
|
||||
var bakedRefs: protocol.ReferencesResponseItem[] = references.map((ref) => {
|
||||
var bakedRefs: protocol.ReferencesResponseItem[] = references.map(ref => {
|
||||
var start = compilerService.host.positionToLineOffset(ref.fileName, ref.textSpan.start);
|
||||
var refLineSpan = compilerService.host.lineToTextSpan(ref.fileName, start.line - 1);
|
||||
var snap = compilerService.host.getScriptSnapshot(ref.fileName);
|
||||
@@ -398,12 +430,12 @@ module ts.server {
|
||||
};
|
||||
}
|
||||
|
||||
openClientFile(fileName: string) {
|
||||
openClientFile({ file: fileName }: protocol.OpenRequestArgs) {
|
||||
var file = ts.normalizePath(fileName);
|
||||
this.projectService.openClientFile(file);
|
||||
}
|
||||
|
||||
getQuickInfo(line: number, offset: number, fileName: string): protocol.QuickInfoResponseBody {
|
||||
getQuickInfo({ line, offset, file: fileName }: protocol.FileLocationRequestArgs): protocol.QuickInfoResponseBody {
|
||||
var file = ts.normalizePath(fileName);
|
||||
var project = this.projectService.getProjectForFile(file);
|
||||
if (!project) {
|
||||
@@ -429,7 +461,7 @@ module ts.server {
|
||||
};
|
||||
}
|
||||
|
||||
getFormattingEditsForRange(line: number, offset: number, endLine: number, endOffset: number, fileName: string): protocol.CodeEdit[] {
|
||||
getFormattingEditsForRange({line, offset, endLine, endOffset, file: fileName}: protocol.FormatRequestArgs): protocol.CodeEdit[] {
|
||||
var file = ts.normalizePath(fileName);
|
||||
var project = this.projectService.getProjectForFile(file);
|
||||
if (!project) {
|
||||
@@ -456,7 +488,7 @@ module ts.server {
|
||||
});
|
||||
}
|
||||
|
||||
getFormattingEditsAfterKeystroke(line: number, offset: number, key: string, fileName: string): protocol.CodeEdit[] {
|
||||
getFormattingEditsAfterKeystroke({line, offset, key, file: fileName}: protocol.FormatOnKeyRequestArgs): protocol.CodeEdit[] {
|
||||
var file = ts.normalizePath(fileName);
|
||||
|
||||
var project = this.projectService.getProjectForFile(file);
|
||||
@@ -529,7 +561,7 @@ module ts.server {
|
||||
});
|
||||
}
|
||||
|
||||
getCompletions(line: number, offset: number, prefix: string, fileName: string): protocol.CompletionEntry[] {
|
||||
getCompletions({ line, offset, prefix, file: fileName}: protocol.CompletionsRequestArgs): protocol.CompletionEntry[] {
|
||||
if (!prefix) {
|
||||
prefix = "";
|
||||
}
|
||||
@@ -555,8 +587,7 @@ module ts.server {
|
||||
}, []).sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
|
||||
getCompletionEntryDetails(line: number, offset: number,
|
||||
entryNames: string[], fileName: string): protocol.CompletionEntryDetails[] {
|
||||
getCompletionEntryDetails({ line, offset, entryNames, file: fileName}: protocol.CompletionDetailsRequestArgs): protocol.CompletionEntryDetails[] {
|
||||
var file = ts.normalizePath(fileName);
|
||||
var project = this.projectService.getProjectForFile(file);
|
||||
if (!project) {
|
||||
@@ -575,20 +606,20 @@ module ts.server {
|
||||
}, []);
|
||||
}
|
||||
|
||||
getSignatureHelpItems(line: number, offset: number, fileName: string): protocol.SignatureHelpItems {
|
||||
getSignatureHelpItems({ line, offset, file: fileName }: protocol.SignatureHelpRequestArgs): protocol.SignatureHelpItems {
|
||||
var file = ts.normalizePath(fileName);
|
||||
var project = this.projectService.getProjectForFile(file);
|
||||
if (!project) {
|
||||
throw Errors.NoProject;
|
||||
}
|
||||
|
||||
|
||||
var compilerService = project.compilerService;
|
||||
var position = compilerService.host.lineOffsetToPosition(file, line, offset);
|
||||
var helpItems = compilerService.languageService.getSignatureHelpItems(file, position);
|
||||
if (!helpItems) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
var span = helpItems.applicableSpan;
|
||||
var result: protocol.SignatureHelpItems = {
|
||||
items: helpItems.items,
|
||||
@@ -600,11 +631,11 @@ module ts.server {
|
||||
argumentIndex: helpItems.argumentIndex,
|
||||
argumentCount: helpItems.argumentCount,
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
getDiagnostics(delay: number, fileNames: string[]) {
|
||||
|
||||
getDiagnostics({ delay, files: fileNames }: protocol.GeterrRequestArgs): void {
|
||||
var checkList = fileNames.reduce((accum: PendingErrorCheck[], fileName: string) => {
|
||||
fileName = ts.normalizePath(fileName);
|
||||
var project = this.projectService.getProjectForFile(fileName);
|
||||
@@ -615,11 +646,11 @@ module ts.server {
|
||||
}, []);
|
||||
|
||||
if (checkList.length > 0) {
|
||||
this.updateErrorCheck(checkList, this.changeSeq,(n) => n == this.changeSeq, delay)
|
||||
this.updateErrorCheck(checkList, this.changeSeq, (n) => n == this.changeSeq, delay)
|
||||
}
|
||||
}
|
||||
|
||||
change(line: number, offset: number, endLine: number, endOffset: number, insertString: string, fileName: string) {
|
||||
change({ line, offset, endLine, endOffset, insertString, file: fileName }: protocol.ChangeRequestArgs): void {
|
||||
var file = ts.normalizePath(fileName);
|
||||
var project = this.projectService.getProjectForFile(file);
|
||||
if (project) {
|
||||
@@ -634,7 +665,7 @@ module ts.server {
|
||||
}
|
||||
}
|
||||
|
||||
reload(fileName: string, tempFileName: string, reqSeq = 0) {
|
||||
reload({ file: fileName, tmpfile: tempFileName }: protocol.ReloadRequestArgs, reqSeq = 0): void {
|
||||
var file = ts.normalizePath(fileName);
|
||||
var tmpfile = ts.normalizePath(tempFileName);
|
||||
var project = this.projectService.getProjectForFile(file);
|
||||
@@ -647,7 +678,7 @@ module ts.server {
|
||||
}
|
||||
}
|
||||
|
||||
saveToTmp(fileName: string, tempFileName: string) {
|
||||
saveToTmp({ file: fileName, tmpfile: tempFileName }: protocol.SavetoRequestArgs): void {
|
||||
var file = ts.normalizePath(fileName);
|
||||
var tmpfile = ts.normalizePath(tempFileName);
|
||||
|
||||
@@ -657,7 +688,7 @@ module ts.server {
|
||||
}
|
||||
}
|
||||
|
||||
closeClientFile(fileName: string) {
|
||||
closeClientFile({ file: fileName }: protocol.FileRequestArgs) {
|
||||
var file = ts.normalizePath(fileName);
|
||||
this.projectService.closeClientFile(file);
|
||||
}
|
||||
@@ -681,7 +712,7 @@ module ts.server {
|
||||
}));
|
||||
}
|
||||
|
||||
getNavigationBarItems(fileName: string): protocol.NavigationBarItem[] {
|
||||
getNavigationBarItems({ file: fileName }: protocol.FileRequestArgs): protocol.NavigationBarItem[]{
|
||||
var file = ts.normalizePath(fileName);
|
||||
var project = this.projectService.getProjectForFile(file);
|
||||
if (!project) {
|
||||
@@ -697,7 +728,7 @@ module ts.server {
|
||||
return this.decorateNavigationBarItem(project, fileName, items);
|
||||
}
|
||||
|
||||
getNavigateToItems(searchValue: string, fileName: string, maxResultCount?: number): protocol.NavtoItem[] {
|
||||
getNavigateToItems({ searchValue, file: fileName, maxResultCount }: protocol.NavtoRequestArgs): protocol.NavtoItem[]{
|
||||
var file = ts.normalizePath(fileName);
|
||||
var project = this.projectService.getProjectForFile(file);
|
||||
if (!project) {
|
||||
@@ -736,7 +767,7 @@ module ts.server {
|
||||
});
|
||||
}
|
||||
|
||||
getBraceMatching(line: number, offset: number, fileName: string): protocol.TextSpan[] {
|
||||
getBraceMatching({ line, offset, file: fileName }: protocol.FileLocationRequestArgs): protocol.TextSpan[]{
|
||||
var file = ts.normalizePath(fileName);
|
||||
|
||||
var project = this.projectService.getProjectForFile(file);
|
||||
@@ -758,6 +789,9 @@ module ts.server {
|
||||
}));
|
||||
}
|
||||
|
||||
exit() {
|
||||
}
|
||||
|
||||
onMessage(message: string) {
|
||||
if (this.logger.isVerbose()) {
|
||||
this.logger.info("request: " + message);
|
||||
@@ -769,110 +803,97 @@ module ts.server {
|
||||
var errorMessage: string;
|
||||
var responseRequired = true;
|
||||
switch (request.command) {
|
||||
case CommandNames.Exit: {
|
||||
this.exit();
|
||||
responseRequired = false;
|
||||
break;
|
||||
}
|
||||
case CommandNames.Definition: {
|
||||
var defArgs = <protocol.FileLocationRequestArgs>request.arguments;
|
||||
response = this.getDefinition(defArgs.line, defArgs.offset, defArgs.file);
|
||||
response = this.getDefinition(<protocol.FileLocationRequestArgs>request.arguments);
|
||||
break;
|
||||
}
|
||||
case CommandNames.References: {
|
||||
var refArgs = <protocol.FileLocationRequestArgs>request.arguments;
|
||||
response = this.getReferences(refArgs.line, refArgs.offset, refArgs.file);
|
||||
response = this.getReferences(<protocol.FileLocationRequestArgs>request.arguments);
|
||||
break;
|
||||
}
|
||||
case CommandNames.Rename: {
|
||||
var renameArgs = <protocol.RenameRequestArgs>request.arguments;
|
||||
response = this.getRenameLocations(renameArgs.line, renameArgs.offset, renameArgs.file, renameArgs.findInComments, renameArgs.findInStrings);
|
||||
response = this.getRenameLocations(<protocol.RenameRequestArgs>request.arguments);
|
||||
break;
|
||||
}
|
||||
case CommandNames.Open: {
|
||||
var openArgs = <protocol.OpenRequestArgs>request.arguments;
|
||||
this.openClientFile(openArgs.file);
|
||||
this.openClientFile(<protocol.OpenRequestArgs>request.arguments);
|
||||
responseRequired = false;
|
||||
break;
|
||||
}
|
||||
case CommandNames.Quickinfo: {
|
||||
var quickinfoArgs = <protocol.FileLocationRequestArgs>request.arguments;
|
||||
response = this.getQuickInfo(quickinfoArgs.line, quickinfoArgs.offset, quickinfoArgs.file);
|
||||
response = this.getQuickInfo(<protocol.FileLocationRequestArgs>request.arguments);
|
||||
break;
|
||||
}
|
||||
case CommandNames.Format: {
|
||||
var formatArgs = <protocol.FormatRequestArgs>request.arguments;
|
||||
response = this.getFormattingEditsForRange(formatArgs.line, formatArgs.offset, formatArgs.endLine, formatArgs.endOffset, formatArgs.file);
|
||||
response = this.getFormattingEditsForRange(<protocol.FormatRequestArgs>request.arguments);
|
||||
break;
|
||||
}
|
||||
case CommandNames.Formatonkey: {
|
||||
var formatOnKeyArgs = <protocol.FormatOnKeyRequestArgs>request.arguments;
|
||||
response = this.getFormattingEditsAfterKeystroke(formatOnKeyArgs.line, formatOnKeyArgs.offset, formatOnKeyArgs.key, formatOnKeyArgs.file);
|
||||
response = this.getFormattingEditsAfterKeystroke(<protocol.FormatOnKeyRequestArgs>request.arguments);
|
||||
break;
|
||||
}
|
||||
case CommandNames.Completions: {
|
||||
var completionsArgs = <protocol.CompletionsRequestArgs>request.arguments;
|
||||
response = this.getCompletions(completionsArgs.line, completionsArgs.offset, completionsArgs.prefix, completionsArgs.file);
|
||||
response = this.getCompletions(<protocol.CompletionsRequestArgs>request.arguments);
|
||||
break;
|
||||
}
|
||||
case CommandNames.CompletionDetails: {
|
||||
var completionDetailsArgs = <protocol.CompletionDetailsRequestArgs>request.arguments;
|
||||
response =
|
||||
this.getCompletionEntryDetails(completionDetailsArgs.line,completionDetailsArgs.offset,
|
||||
completionDetailsArgs.entryNames,completionDetailsArgs.file);
|
||||
response = this.getCompletionEntryDetails(<protocol.CompletionDetailsRequestArgs>request.arguments);
|
||||
break;
|
||||
}
|
||||
case CommandNames.SignatureHelp: {
|
||||
var signatureHelpArgs = <protocol.SignatureHelpRequestArgs>request.arguments;
|
||||
response = this.getSignatureHelpItems(signatureHelpArgs.line, signatureHelpArgs.offset, signatureHelpArgs.file);
|
||||
response = this.getSignatureHelpItems(<protocol.SignatureHelpRequestArgs>request.arguments);
|
||||
break;
|
||||
}
|
||||
case CommandNames.Geterr: {
|
||||
var geterrArgs = <protocol.GeterrRequestArgs>request.arguments;
|
||||
response = this.getDiagnostics(geterrArgs.delay, geterrArgs.files);
|
||||
this.getDiagnostics(<protocol.GeterrRequestArgs>request.arguments);
|
||||
responseRequired = false;
|
||||
break;
|
||||
}
|
||||
case CommandNames.Change: {
|
||||
var changeArgs = <protocol.ChangeRequestArgs>request.arguments;
|
||||
this.change(changeArgs.line, changeArgs.offset, changeArgs.endLine, changeArgs.endOffset,
|
||||
changeArgs.insertString, changeArgs.file);
|
||||
this.change(<protocol.ChangeRequestArgs>request.arguments);
|
||||
responseRequired = false;
|
||||
break;
|
||||
}
|
||||
case CommandNames.Configure: {
|
||||
var configureArgs = <protocol.ConfigureRequestArguments>request.arguments;
|
||||
this.projectService.setHostConfiguration(configureArgs);
|
||||
this.projectService.setHostConfiguration(<protocol.ConfigureRequestArguments>request.arguments);
|
||||
this.output(undefined, CommandNames.Configure, request.seq);
|
||||
responseRequired = false;
|
||||
break;
|
||||
}
|
||||
case CommandNames.Reload: {
|
||||
var reloadArgs = <protocol.ReloadRequestArgs>request.arguments;
|
||||
this.reload(reloadArgs.file, reloadArgs.tmpfile, request.seq);
|
||||
this.reload(<protocol.ReloadRequestArgs>request.arguments);
|
||||
responseRequired = false;
|
||||
break;
|
||||
}
|
||||
case CommandNames.Saveto: {
|
||||
var savetoArgs = <protocol.SavetoRequestArgs>request.arguments;
|
||||
this.saveToTmp(savetoArgs.file, savetoArgs.tmpfile);
|
||||
this.saveToTmp(<protocol.SavetoRequestArgs>request.arguments);
|
||||
responseRequired = false;
|
||||
break;
|
||||
}
|
||||
case CommandNames.Close: {
|
||||
var closeArgs = <protocol.FileRequestArgs>request.arguments;
|
||||
this.closeClientFile(closeArgs.file);
|
||||
this.closeClientFile(<protocol.FileRequestArgs>request.arguments);
|
||||
responseRequired = false;
|
||||
break;
|
||||
}
|
||||
case CommandNames.Navto: {
|
||||
var navtoArgs = <protocol.NavtoRequestArgs>request.arguments;
|
||||
response = this.getNavigateToItems(navtoArgs.searchValue, navtoArgs.file, navtoArgs.maxResultCount);
|
||||
response = this.getNavigateToItems(<protocol.NavtoRequestArgs>request.arguments);
|
||||
break;
|
||||
}
|
||||
case CommandNames.Brace: {
|
||||
var braceArguments = <protocol.FileLocationRequestArgs>request.arguments;
|
||||
response = this.getBraceMatching(braceArguments.line, braceArguments.offset, braceArguments.file);
|
||||
response = this.getBraceMatching(<protocol.FileLocationRequestArgs>request.arguments);
|
||||
break;
|
||||
}
|
||||
case CommandNames.NavBar: {
|
||||
var navBarArgs = <protocol.FileRequestArgs>request.arguments;
|
||||
response = this.getNavigationBarItems(navBarArgs.file);
|
||||
response = this.getNavigationBarItems(<protocol.FileRequestArgs>request.arguments);
|
||||
break;
|
||||
}
|
||||
case CommandNames.Occurrences: {
|
||||
response = this.getOccurrences(<protocol.FileLocationRequestArgs>request.arguments);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -135,11 +135,21 @@ module ts {
|
||||
findReferences(fileName: string, position: number): string;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Returns a JSON-encoded value of the type:
|
||||
* { fileName: string; textSpan: { start: number; length: number}; isWriteAccess: boolean }[]
|
||||
*/
|
||||
getOccurrencesAtPosition(fileName: string, position: number): string;
|
||||
|
||||
/**
|
||||
* Returns a JSON-encoded value of the type:
|
||||
* { fileName: string; highlights: { start: number; length: number, isDefinition: boolean }[] }[]
|
||||
*
|
||||
* @param fileToSearch A JSON encoded string[] containing the file names that should be
|
||||
* considered when searching.
|
||||
*/
|
||||
getDocumentHighlights(fileName: string, position: number, filesToSearch: string): string;
|
||||
|
||||
/**
|
||||
* Returns a JSON-encoded value of the type:
|
||||
* { name: string; kind: string; kindModifiers: string; containerName: string; containerKind: string; matchKind: string; fileName: string; textSpan: { start: number; length: number}; } [] = [];
|
||||
@@ -590,6 +600,14 @@ module ts {
|
||||
});
|
||||
}
|
||||
|
||||
public getDocumentHighlights(fileName: string, position: number, filesToSearch: string): string {
|
||||
return this.forwardJSONCall(
|
||||
"getDocumentHighlights('" + fileName + "', " + position + ")",
|
||||
() => {
|
||||
return this.languageService.getDocumentHighlights(fileName, position, JSON.parse(filesToSearch));
|
||||
});
|
||||
}
|
||||
|
||||
/// COMPLETION LISTS
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user