Move updated code to the ts namespace

This commit is contained in:
Mohamed Hegazy 2014-07-24 17:36:06 -07:00
parent 7d5da6c8ab
commit 6ca9a1a6d8
7 changed files with 183 additions and 187 deletions

View file

@ -4,7 +4,7 @@
///<reference path='references.ts' />
module TypeScript.Services.Breakpoints {
function createBreakpointSpanInfo(parentElement: TypeScript.ISyntaxElement, ...childElements: TypeScript.ISyntaxElement[]): SpanInfo {
function createBreakpointSpanInfo(parentElement: TypeScript.ISyntaxElement, ...childElements: TypeScript.ISyntaxElement[]): ts.SpanInfo {
if (!parentElement) {
return null;
}
@ -34,7 +34,7 @@ module TypeScript.Services.Breakpoints {
};
}
function createBreakpointSpanInfoWithLimChar(startElement: TypeScript.ISyntaxElement, limChar: number): SpanInfo {
function createBreakpointSpanInfoWithLimChar(startElement: TypeScript.ISyntaxElement, limChar: number): ts.SpanInfo {
return {
minChar: start(startElement),
limChar: limChar
@ -45,7 +45,7 @@ module TypeScript.Services.Breakpoints {
constructor(private posLine: number, private lineMap: TypeScript.LineMap) {
}
private breakpointSpanOfToken(positionedToken: TypeScript.ISyntaxToken): SpanInfo {
private breakpointSpanOfToken(positionedToken: TypeScript.ISyntaxToken): ts.SpanInfo {
switch (positionedToken.kind()) {
case TypeScript.SyntaxKind.OpenBraceToken:
return this.breakpointSpanOfOpenBrace(positionedToken);
@ -74,7 +74,7 @@ module TypeScript.Services.Breakpoints {
return this.breakpointSpanOfContainingNode(positionedToken);
}
private breakpointSpanOfOpenBrace(openBraceToken: TypeScript.ISyntaxToken): SpanInfo {
private breakpointSpanOfOpenBrace(openBraceToken: TypeScript.ISyntaxToken): ts.SpanInfo {
var container = Syntax.containingNode(openBraceToken);
if (container) {
var originalContainer = container;
@ -168,7 +168,7 @@ module TypeScript.Services.Breakpoints {
return null;
}
private breakpointSpanOfCloseBrace(closeBraceToken: TypeScript.ISyntaxToken): SpanInfo {
private breakpointSpanOfCloseBrace(closeBraceToken: TypeScript.ISyntaxToken): ts.SpanInfo {
var container = Syntax.containingNode(closeBraceToken);
if (container) {
var originalContainer = container;
@ -243,7 +243,7 @@ module TypeScript.Services.Breakpoints {
}
private breakpointSpanOfComma(commaToken: TypeScript.ISyntaxToken): SpanInfo {
private breakpointSpanOfComma(commaToken: TypeScript.ISyntaxToken): ts.SpanInfo {
var commaParent = commaToken.parent;
if (isSeparatedList(commaParent)) {
var grandParent = commaParent.parent;
@ -271,7 +271,7 @@ module TypeScript.Services.Breakpoints {
return this.breakpointSpanOfContainingNode(commaToken);
}
private breakpointSpanOfCloseParen(closeParenToken: TypeScript.ISyntaxToken): SpanInfo {
private breakpointSpanOfCloseParen(closeParenToken: TypeScript.ISyntaxToken): ts.SpanInfo {
var closeParenParent = closeParenToken.parent;
if (closeParenParent) {
switch (closeParenParent.kind()) {
@ -293,7 +293,7 @@ module TypeScript.Services.Breakpoints {
return blockSyntax.statements && blockSyntax.statements.length != 0;
}
private breakpointSpanOfFirstStatementInBlock(blockNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfFirstStatementInBlock(blockNode: TypeScript.ISyntaxNode): ts.SpanInfo {
if (!blockNode) {
return null;
}
@ -316,7 +316,7 @@ module TypeScript.Services.Breakpoints {
}
}
private breakpointSpanOfLastStatementInBlock(blockNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfLastStatementInBlock(blockNode: TypeScript.ISyntaxNode): ts.SpanInfo {
if (!blockNode) {
return null;
}
@ -339,7 +339,7 @@ module TypeScript.Services.Breakpoints {
}
}
private breakpointSpanOfFirstChildOfSyntaxList(positionedList: TypeScript.ISyntaxNodeOrToken[]): SpanInfo {
private breakpointSpanOfFirstChildOfSyntaxList(positionedList: TypeScript.ISyntaxNodeOrToken[]): ts.SpanInfo {
if (!positionedList) {
return null;
}
@ -363,7 +363,7 @@ module TypeScript.Services.Breakpoints {
}
}
private breakpointSpanOfLastChildOfSyntaxList(positionedList: TypeScript.ISyntaxNodeOrToken[]): SpanInfo {
private breakpointSpanOfLastChildOfSyntaxList(positionedList: TypeScript.ISyntaxNodeOrToken[]): ts.SpanInfo {
if (!positionedList) {
return null;
}
@ -385,7 +385,7 @@ module TypeScript.Services.Breakpoints {
}
}
private breakpointSpanOfNode(positionedNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfNode(positionedNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var node = positionedNode;
switch (node.kind()) {
// Declarations with elements
@ -552,12 +552,12 @@ module TypeScript.Services.Breakpoints {
return false;
}
private breakpointOfLeftOfCommaExpression(commaExpressionNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointOfLeftOfCommaExpression(commaExpressionNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var commaExpression = <TypeScript.BinaryExpressionSyntax>commaExpressionNode;
return this.breakpointSpanOf(commaExpression.left);
}
private breakpointOfExpression(expressionNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointOfExpression(expressionNode: TypeScript.ISyntaxNode): ts.SpanInfo {
if (this.isInitializerOfForStatement(expressionNode) ||
this.isConditionOfForStatement(expressionNode) ||
this.isIncrememtorOfForStatement(expressionNode)) {
@ -582,7 +582,7 @@ module TypeScript.Services.Breakpoints {
return this.breakpointSpanOfContainingNode(expressionNode);
}
private breakpointSpanOfStatement(statementNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfStatement(statementNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var statement = statementNode;
if (statement.kind() == TypeScript.SyntaxKind.EmptyStatement) {
return null;
@ -722,7 +722,7 @@ module TypeScript.Services.Breakpoints {
return positionedNode && !TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(positionedNode);
}
private breakpointSpanOfDeclarationWithElements(positionedNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfDeclarationWithElements(positionedNode: TypeScript.ISyntaxNode): ts.SpanInfo {
if (!this.canHaveBreakpointInDeclaration(positionedNode)) {
return null;
}
@ -751,7 +751,7 @@ module TypeScript.Services.Breakpoints {
return !!varDeclaratorSyntax.equalsValueClause;
}
private breakpointSpanOfVariableDeclarator(varDeclaratorNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfVariableDeclarator(varDeclaratorNode: TypeScript.ISyntaxNode): ts.SpanInfo {
if (!this.canHaveBreakpointInVariableDeclarator(varDeclaratorNode)) {
return null;
}
@ -799,7 +799,7 @@ module TypeScript.Services.Breakpoints {
return false;
}
private breakpointSpanOfVariableDeclaration(varDeclarationNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfVariableDeclaration(varDeclarationNode: TypeScript.ISyntaxNode): ts.SpanInfo {
if (!this.canHaveBreakpointInDeclaration(varDeclarationNode)) {
return null;
}
@ -830,7 +830,7 @@ module TypeScript.Services.Breakpoints {
return this.canHaveBreakpointInVariableDeclaration(<TypeScript.ISyntaxNode>variableStatement.variableDeclaration);
}
private breakpointSpanOfVariableStatement(varStatementNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfVariableStatement(varStatementNode: TypeScript.ISyntaxNode): ts.SpanInfo {
if (!this.canHaveBreakpointInVariableStatement(varStatementNode)) {
return null;
}
@ -842,7 +842,7 @@ module TypeScript.Services.Breakpoints {
return createBreakpointSpanInfoWithLimChar(varStatementNode, end(childAt(varDeclarators, 0)));
}
private breakpointSpanOfParameter(parameterNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfParameter(parameterNode: TypeScript.ISyntaxNode): ts.SpanInfo {
if (parameterNode.parent.kind() === SyntaxKind.SimpleArrowFunctionExpression) {
return this.breakpointSpanOfNode(<ISyntaxNode>parameterNode.parent);
}
@ -860,7 +860,7 @@ module TypeScript.Services.Breakpoints {
}
}
private breakpointSpanOfMemberVariableDeclaration(memberVarDeclarationNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfMemberVariableDeclaration(memberVarDeclarationNode: TypeScript.ISyntaxNode): ts.SpanInfo {
if (TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(memberVarDeclarationNode)) {
return null;
}
@ -874,7 +874,7 @@ module TypeScript.Services.Breakpoints {
}
}
private breakpointSpanOfImportDeclaration(importDeclarationNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfImportDeclaration(importDeclarationNode: TypeScript.ISyntaxNode): ts.SpanInfo {
if (TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(importDeclarationNode)) {
return null;
}
@ -883,7 +883,7 @@ module TypeScript.Services.Breakpoints {
return createBreakpointSpanInfo(importDeclarationNode, importSyntax.modifiers, importSyntax.importKeyword, importSyntax.identifier, importSyntax.equalsToken, importSyntax.moduleReference);
}
private breakpointSpanOfEnumDeclaration(enumDeclarationNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfEnumDeclaration(enumDeclarationNode: TypeScript.ISyntaxNode): ts.SpanInfo {
if (!this.canHaveBreakpointInDeclaration(enumDeclarationNode)) {
return null;
}
@ -891,7 +891,7 @@ module TypeScript.Services.Breakpoints {
return createBreakpointSpanInfo(enumDeclarationNode);
}
private breakpointSpanOfFirstEnumElement(enumDeclarationNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfFirstEnumElement(enumDeclarationNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var enumDeclarationSyntax = <TypeScript.EnumDeclarationSyntax>enumDeclarationNode;
var enumElements = enumDeclarationSyntax.enumElements;
if (enumElements && childCount(enumElements)) {
@ -901,7 +901,7 @@ module TypeScript.Services.Breakpoints {
return null;
}
private breakpointSpanOfEnumElement(enumElementNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfEnumElement(enumElementNode: TypeScript.ISyntaxNode): ts.SpanInfo {
if (TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(enumElementNode)) {
return null;
}
@ -909,45 +909,45 @@ module TypeScript.Services.Breakpoints {
return createBreakpointSpanInfo(enumElementNode);
}
private breakpointSpanOfIfStatement(ifStatementNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfIfStatement(ifStatementNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var ifStatement = <TypeScript.IfStatementSyntax>ifStatementNode;
return createBreakpointSpanInfo(ifStatementNode, ifStatement.ifKeyword, ifStatement.openParenToken, ifStatement.condition, ifStatement.closeParenToken);
}
private breakpointSpanOfElseClause(elseClauseNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfElseClause(elseClauseNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var elseClause = <TypeScript.ElseClauseSyntax>elseClauseNode;
return this.breakpointSpanOf(elseClause.statement);
}
private breakpointSpanOfForInStatement(forInStatementNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfForInStatement(forInStatementNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var forInStatement = <TypeScript.ForInStatementSyntax>forInStatementNode;
return createBreakpointSpanInfo(forInStatementNode, forInStatement.forKeyword, forInStatement.openParenToken, forInStatement.variableDeclaration,
forInStatement.left, forInStatement.inKeyword, forInStatement.expression, forInStatement.closeParenToken);
}
private breakpointSpanOfForStatement(forStatementNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfForStatement(forStatementNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var forStatement = <TypeScript.ForStatementSyntax>forStatementNode;
return this.breakpointSpanOf(forStatement.variableDeclaration
? <TypeScript.ISyntaxElement>forStatement.variableDeclaration
: forStatement.initializer);
}
private breakpointSpanOfWhileStatement(whileStatementNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfWhileStatement(whileStatementNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var whileStatement = <TypeScript.WhileStatementSyntax>whileStatementNode;
return createBreakpointSpanInfo(whileStatementNode, whileStatement.whileKeyword, whileStatement.openParenToken, whileStatement.condition, whileStatement.closeParenToken);
}
private breakpointSpanOfDoStatement(doStatementNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfDoStatement(doStatementNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var doStatement = <TypeScript.DoStatementSyntax>doStatementNode;
return createBreakpointSpanInfo(doStatementNode, doStatement.whileKeyword, doStatement.openParenToken, doStatement.condition, doStatement.closeParenToken);
}
private breakpointSpanOfSwitchStatement(switchStatementNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfSwitchStatement(switchStatementNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var switchStatement = <TypeScript.SwitchStatementSyntax>switchStatementNode;
return createBreakpointSpanInfo(switchStatementNode, switchStatement.switchKeyword, switchStatement.openParenToken, switchStatement.expression, switchStatement.closeParenToken);
}
private breakpointSpanOfFirstStatementOfFirstCaseClause(switchStatementNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfFirstStatementOfFirstCaseClause(switchStatementNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var switchStatement = <TypeScript.SwitchStatementSyntax>switchStatementNode;
if (switchStatement.switchClauses && switchStatement.switchClauses.length == 0) {
return null;
@ -964,7 +964,7 @@ module TypeScript.Services.Breakpoints {
return this.breakpointSpanOfFirstChildOfSyntaxList(statements);
}
private breakpointSpanOfLastStatementOfLastCaseClause(switchStatementNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfLastStatementOfLastCaseClause(switchStatementNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var switchStatement = <TypeScript.SwitchStatementSyntax>switchStatementNode;
if (switchStatement.switchClauses && switchStatement.switchClauses.length == 0) {
return null;
@ -981,37 +981,37 @@ module TypeScript.Services.Breakpoints {
return this.breakpointSpanOfLastChildOfSyntaxList(statements);
}
private breakpointSpanOfCaseSwitchClause(caseClauseNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfCaseSwitchClause(caseClauseNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var caseSwitchClause = <TypeScript.CaseSwitchClauseSyntax>caseClauseNode;
return this.breakpointSpanOfFirstChildOfSyntaxList(caseSwitchClause.statements);
}
private breakpointSpanOfDefaultSwitchClause(defaultSwithClauseNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfDefaultSwitchClause(defaultSwithClauseNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var defaultSwitchClause = <TypeScript.DefaultSwitchClauseSyntax>defaultSwithClauseNode;
return this.breakpointSpanOfFirstChildOfSyntaxList(defaultSwitchClause.statements);
}
private breakpointSpanOfWithStatement(withStatementNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfWithStatement(withStatementNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var withStatement = <TypeScript.WithStatementSyntax>withStatementNode;
return this.breakpointSpanOf(withStatement.statement);
}
private breakpointSpanOfTryStatement(tryStatementNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfTryStatement(tryStatementNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var tryStatement = <TypeScript.TryStatementSyntax>tryStatementNode;
return this.breakpointSpanOfFirstStatementInBlock(<TypeScript.ISyntaxNode>tryStatement.block);
}
private breakpointSpanOfCatchClause(catchClauseNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfCatchClause(catchClauseNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var catchClause = <TypeScript.CatchClauseSyntax>catchClauseNode;
return createBreakpointSpanInfo(catchClauseNode, catchClause.catchKeyword, catchClause.openParenToken, catchClause.identifier, catchClause.typeAnnotation, catchClause.closeParenToken);
}
private breakpointSpanOfFinallyClause(finallyClauseNode: TypeScript.ISyntaxNode): SpanInfo {
private breakpointSpanOfFinallyClause(finallyClauseNode: TypeScript.ISyntaxNode): ts.SpanInfo {
var finallyClause = <TypeScript.FinallyClauseSyntax>finallyClauseNode;
return this.breakpointSpanOfFirstStatementInBlock(<TypeScript.ISyntaxNode>finallyClause.block);
}
private breakpointSpanOfParenthesizedArrowFunctionExpression(arrowFunctionExpression: ParenthesizedArrowFunctionExpressionSyntax): SpanInfo {
private breakpointSpanOfParenthesizedArrowFunctionExpression(arrowFunctionExpression: ParenthesizedArrowFunctionExpressionSyntax): ts.SpanInfo {
if (arrowFunctionExpression.block) {
return this.breakpointSpanOfFirstStatementInBlock(arrowFunctionExpression.block);
}
@ -1020,7 +1020,7 @@ module TypeScript.Services.Breakpoints {
}
}
private breakpointSpanOfSimpleArrowFunctionExpression(arrowFunctionExpression: SimpleArrowFunctionExpressionSyntax): SpanInfo {
private breakpointSpanOfSimpleArrowFunctionExpression(arrowFunctionExpression: SimpleArrowFunctionExpressionSyntax): ts.SpanInfo {
if (arrowFunctionExpression.block) {
return this.breakpointSpanOfFirstStatementInBlock(arrowFunctionExpression.block);
}
@ -1029,7 +1029,7 @@ module TypeScript.Services.Breakpoints {
}
}
private breakpointSpanOfContainingNode(positionedElement: ISyntaxElement): SpanInfo {
private breakpointSpanOfContainingNode(positionedElement: ISyntaxElement): ts.SpanInfo {
var current = positionedElement.parent;
while (!isNode(current)) {
current = current.parent;
@ -1038,7 +1038,7 @@ module TypeScript.Services.Breakpoints {
return this.breakpointSpanOf(current);
}
private breakpointSpanIfStartsOnSameLine(positionedElement: TypeScript.ISyntaxElement): SpanInfo {
private breakpointSpanIfStartsOnSameLine(positionedElement: TypeScript.ISyntaxElement): ts.SpanInfo {
if (positionedElement && this.posLine == this.lineMap.getLineNumberFromPosition(start(positionedElement))) {
return this.breakpointSpanOf(positionedElement);
}
@ -1046,7 +1046,7 @@ module TypeScript.Services.Breakpoints {
return null;
}
public breakpointSpanOf(positionedElement: TypeScript.ISyntaxElement): SpanInfo {
public breakpointSpanOf(positionedElement: TypeScript.ISyntaxElement): ts.SpanInfo {
if (!positionedElement) {
return null;
}
@ -1075,7 +1075,7 @@ module TypeScript.Services.Breakpoints {
}
}
export function getBreakpointLocation(syntaxTree: TypeScript.SyntaxTree, askedPos: number): SpanInfo {
export function getBreakpointLocation(syntaxTree: TypeScript.SyntaxTree, askedPos: number): ts.SpanInfo {
// Cannot set breakpoint in dts file
if (TypeScript.isDTSFile(syntaxTree.fileName())) {
return null;

View file

@ -19,28 +19,28 @@ module TypeScript.Services.Formatting {
export class FormattingManager {
private options: FormattingOptions;
constructor(private syntaxTree: SyntaxTree, private snapshot: ITextSnapshot, private rulesProvider: RulesProvider, editorOptions: TypeScript.Services.EditorOptions) {
constructor(private syntaxTree: SyntaxTree, private snapshot: ITextSnapshot, private rulesProvider: RulesProvider, editorOptions: ts.EditorOptions) {
//
// TODO: convert to use FormattingOptions instead of EditorOptions
this.options = new FormattingOptions(!editorOptions.ConvertTabsToSpaces, editorOptions.TabSize, editorOptions.IndentSize, editorOptions.NewLineCharacter)
}
public formatSelection(minChar: number, limChar: number): TypeScript.Services.TextEdit[] {
public formatSelection(minChar: number, limChar: number): ts.TextEdit[] {
var span = TextSpan.fromBounds(minChar, limChar);
return this.formatSpan(span, FormattingRequestKind.FormatSelection);
}
public formatDocument(minChar: number, limChar: number): TypeScript.Services.TextEdit[] {
public formatDocument(minChar: number, limChar: number): ts.TextEdit[] {
var span = TextSpan.fromBounds(minChar, limChar);
return this.formatSpan(span, FormattingRequestKind.FormatDocument);
}
public formatOnPaste(minChar: number, limChar: number): TypeScript.Services.TextEdit[] {
public formatOnPaste(minChar: number, limChar: number): ts.TextEdit[] {
var span = TextSpan.fromBounds(minChar, limChar);
return this.formatSpan(span, FormattingRequestKind.FormatOnPaste);
}
public formatOnSemicolon(caretPosition: number): TypeScript.Services.TextEdit[] {
public formatOnSemicolon(caretPosition: number): ts.TextEdit[] {
var sourceUnit = this.syntaxTree.sourceUnit();
var semicolonPositionedToken = findToken(sourceUnit, caretPosition - 1);
@ -63,7 +63,7 @@ module TypeScript.Services.Formatting {
return [];
}
public formatOnClosingCurlyBrace(caretPosition: number): TypeScript.Services.TextEdit[] {
public formatOnClosingCurlyBrace(caretPosition: number): ts.TextEdit[] {
var sourceUnit = this.syntaxTree.sourceUnit();
var closeBracePositionedToken = findToken(sourceUnit, caretPosition - 1);
@ -86,7 +86,7 @@ module TypeScript.Services.Formatting {
return [];
}
public formatOnEnter(caretPosition: number): TypeScript.Services.TextEdit[] {
public formatOnEnter(caretPosition: number): ts.TextEdit[] {
var lineNumber = this.snapshot.getLineNumberFromPosition(caretPosition);
if (lineNumber > 0) {
@ -103,12 +103,12 @@ module TypeScript.Services.Formatting {
return [];
}
private formatSpan(span: TextSpan, formattingRequestKind: FormattingRequestKind): TypeScript.Services.TextEdit[] {
private formatSpan(span: TextSpan, formattingRequestKind: FormattingRequestKind): ts.TextEdit[] {
// Always format from the beginning of the line
var startLine = this.snapshot.getLineFromPosition(span.start());
span = TextSpan.fromBounds(startLine.startPosition(), span.end());
var result: TypeScript.Services.TextEdit[] = [];
var result: ts.TextEdit[] = [];
var formattingEdits = Formatter.getEdits(span, this.syntaxTree.sourceUnit(), this.options, true, this.snapshot, this.rulesProvider, formattingRequestKind);

View file

@ -18,7 +18,7 @@
module TypeScript.Services.Formatting {
export class RulesProvider {
private globalRules: Rules;
private options: TypeScript.Services.FormatCodeOptions;
private options: ts.FormatCodeOptions;
private activeRules: Rule[];
private rulesMap: RulesMap;
@ -38,8 +38,8 @@ module TypeScript.Services.Formatting {
return this.rulesMap;
}
public ensureUpToDate(options: TypeScript.Services.FormatCodeOptions) {
if (this.options == null || !compareDataObjects(this.options, options)) {
public ensureUpToDate(options: ts.FormatCodeOptions) {
if (this.options == null || !ts.compareDataObjects(this.options, options)) {
var activeRules: Rule[] = TypeScript.timeFunction(this.logger, "RulesProvider: createActiveRules()", () => { return this.createActiveRules(options); });
var rulesMap: RulesMap = TypeScript.timeFunction(this.logger, "RulesProvider: RulesMap.create()", () => { return RulesMap.create(activeRules); });
@ -49,7 +49,7 @@ module TypeScript.Services.Formatting {
}
}
private createActiveRules(options: TypeScript.Services.FormatCodeOptions): Rule[] {
private createActiveRules(options: ts.FormatCodeOptions): Rule[] {
var rules = this.globalRules.HighPriorityCommonRules.slice(0);
if (options.InsertSpaceAfterCommaDelimiter) {

View file

@ -2,7 +2,7 @@
///<reference path='references.ts' />
module TypeScript.Services {
interface LexicalScope {
items: ts.Map<NavigateToItem>;
items: ts.Map<ts.NavigateToItem>;
itemNames: string[];
childScopes: ts.Map<LexicalScope>;
childScopeNames: string[];
@ -17,7 +17,7 @@ module TypeScript.Services {
private createScope(): LexicalScope {
return {
items: TypeScript.createIntrinsicsObject<NavigateToItem>(),
items: TypeScript.createIntrinsicsObject<ts.NavigateToItem>(),
childScopes: TypeScript.createIntrinsicsObject<LexicalScope>(),
childScopeNames: [],
itemNames: []
@ -57,7 +57,7 @@ module TypeScript.Services {
this.currentScope = this.createScope();
}
private collectItems(items: NavigateToItem[], scope = this.currentScope) {
private collectItems(items: ts.NavigateToItem[], scope = this.currentScope) {
scope.itemNames.forEach(item => {
items.push(scope.items[item]);
});
@ -67,7 +67,7 @@ module TypeScript.Services {
});
}
static getListsOfAllScriptLexicalStructure(items: NavigateToItem[], fileName: string, unit: TypeScript.SourceUnitSyntax) {
static getListsOfAllScriptLexicalStructure(items: ts.NavigateToItem[], fileName: string, unit: TypeScript.SourceUnitSyntax) {
var visitor = new GetScriptLexicalStructureWalker(fileName);
visitNodeOrToken(visitor, unit);
visitor.collectItems(items);
@ -81,10 +81,10 @@ module TypeScript.Services {
return;
}
var item: NavigateToItem = {
var item: ts.NavigateToItem = {
name: name,
kind: kind,
matchKind: MatchKind.exact,
matchKind: ts.MatchKind.exact,
fileName: this.fileName,
kindModifiers: this.getKindModifiers(modifiers),
minChar: start(node),
@ -104,7 +104,7 @@ module TypeScript.Services {
Debug.assert(item !== undefined);
var start = TypeScript.start(node);
var span: SpanInfo = {
var span: ts.SpanInfo = {
minChar: start,
limChar: start + width(node)
};
@ -125,7 +125,7 @@ module TypeScript.Services {
result.push(modifiers[i].text());
}
return result.length > 0 ? result.join(',') : ScriptElementKindModifier.none;
return result.length > 0 ? result.join(',') : ts.ScriptElementKindModifier.none;
}
public visitModuleDeclaration(node: TypeScript.ModuleDeclarationSyntax): void {
@ -140,7 +140,7 @@ module TypeScript.Services {
}
else {
var name = names[nameIndex];
var kind = ScriptElementKind.moduleElement;
var kind = ts.ScriptElementKind.moduleElement;
this.createItem(node, node.modifiers, kind, name);
@ -178,7 +178,7 @@ module TypeScript.Services {
public visitClassDeclaration(node: TypeScript.ClassDeclarationSyntax): void {
var name = node.identifier.text();
var kind = ScriptElementKind.classElement;
var kind = ts.ScriptElementKind.classElement;
this.createItem(node, node.modifiers, kind, name);
@ -191,7 +191,7 @@ module TypeScript.Services {
public visitInterfaceDeclaration(node: TypeScript.InterfaceDeclarationSyntax): void {
var name = node.identifier.text();
var kind = ScriptElementKind.interfaceElement;
var kind = ts.ScriptElementKind.interfaceElement;
this.createItem(node, node.modifiers, kind, name);
@ -212,7 +212,7 @@ module TypeScript.Services {
public visitEnumDeclaration(node: TypeScript.EnumDeclarationSyntax): void {
var name = node.identifier.text();
var kind = ScriptElementKind.enumElement;
var kind = ts.ScriptElementKind.enumElement;
this.createItem(node, node.modifiers, kind, name);
@ -224,7 +224,7 @@ module TypeScript.Services {
}
public visitConstructorDeclaration(node: TypeScript.ConstructorDeclarationSyntax): void {
this.createItem(node, TypeScript.Syntax.emptyList<ISyntaxToken>(), ScriptElementKind.constructorImplementationElement, "constructor");
this.createItem(node, TypeScript.Syntax.emptyList<ISyntaxToken>(), ts.ScriptElementKind.constructorImplementationElement, "constructor");
// Search the parameter list of class properties
var parameters = node.callSignature.parameterList.parameters;
@ -236,7 +236,7 @@ module TypeScript.Services {
if (SyntaxUtilities.containsToken(parameter.modifiers, SyntaxKind.PublicKeyword) ||
SyntaxUtilities.containsToken(parameter.modifiers, SyntaxKind.PrivateKeyword)) {
this.createItem(node, parameter.modifiers, ScriptElementKind.memberVariableElement, parameter.identifier.text());
this.createItem(node, parameter.modifiers, ts.ScriptElementKind.memberVariableElement, parameter.identifier.text());
}
}
}
@ -245,19 +245,19 @@ module TypeScript.Services {
}
public visitMemberFunctionDeclaration(node: TypeScript.MemberFunctionDeclarationSyntax): void {
this.createItem(node, node.modifiers, ScriptElementKind.memberFunctionElement, node.propertyName.text());
this.createItem(node, node.modifiers, ts.ScriptElementKind.memberFunctionElement, node.propertyName.text());
// No need to descend into a member function;
}
public visitGetAccessor(node: TypeScript.GetAccessorSyntax): void {
this.createItem(node, node.modifiers, ScriptElementKind.memberGetAccessorElement, node.propertyName.text());
this.createItem(node, node.modifiers, ts.ScriptElementKind.memberGetAccessorElement, node.propertyName.text());
// No need to descend into a member accessor;
}
public visitSetAccessor(node: TypeScript.SetAccessorSyntax): void {
this.createItem(node, node.modifiers, ScriptElementKind.memberSetAccessorElement, node.propertyName.text());
this.createItem(node, node.modifiers, ts.ScriptElementKind.memberSetAccessorElement, node.propertyName.text());
// No need to descend into a member accessor;
}
@ -267,45 +267,45 @@ module TypeScript.Services {
? (<MemberVariableDeclarationSyntax>node.parent).modifiers
: TypeScript.Syntax.emptyList<ISyntaxToken>();
var kind = node.parent.kind() === SyntaxKind.MemberVariableDeclaration
? ScriptElementKind.memberVariableElement
: ScriptElementKind.variableElement;
? ts.ScriptElementKind.memberVariableElement
: ts.ScriptElementKind.variableElement;
this.createItem(node, modifiers, kind, node.propertyName.text());
// No need to descend into a variable declarator;
}
public visitIndexSignature(node: TypeScript.IndexSignatureSyntax): void {
this.createItem(node, TypeScript.Syntax.emptyList<ISyntaxToken>(), ScriptElementKind.indexSignatureElement, "[]");
this.createItem(node, TypeScript.Syntax.emptyList<ISyntaxToken>(), ts.ScriptElementKind.indexSignatureElement, "[]");
// No need to descend into an index signature;
}
public visitEnumElement(node: TypeScript.EnumElementSyntax): void {
this.createItem(node, TypeScript.Syntax.emptyList<ISyntaxToken>(), ScriptElementKind.memberVariableElement, node.propertyName.text());
this.createItem(node, TypeScript.Syntax.emptyList<ISyntaxToken>(), ts.ScriptElementKind.memberVariableElement, node.propertyName.text());
// No need to descend into an enum element;
}
public visitCallSignature(node: TypeScript.CallSignatureSyntax): void {
this.createItem(node, TypeScript.Syntax.emptyList<ISyntaxToken>(), ScriptElementKind.callSignatureElement, "()");
this.createItem(node, TypeScript.Syntax.emptyList<ISyntaxToken>(), ts.ScriptElementKind.callSignatureElement, "()");
// No need to descend into a call signature;
}
public visitConstructSignature(node: TypeScript.ConstructSignatureSyntax): void {
this.createItem(node, TypeScript.Syntax.emptyList<ISyntaxToken>(), ScriptElementKind.constructSignatureElement, "new()");
this.createItem(node, TypeScript.Syntax.emptyList<ISyntaxToken>(), ts.ScriptElementKind.constructSignatureElement, "new()");
// No need to descend into a construct signature;
}
public visitMethodSignature(node: TypeScript.MethodSignatureSyntax): void {
this.createItem(node, TypeScript.Syntax.emptyList<ISyntaxToken>(), ScriptElementKind.memberFunctionElement, node.propertyName.text());
this.createItem(node, TypeScript.Syntax.emptyList<ISyntaxToken>(), ts.ScriptElementKind.memberFunctionElement, node.propertyName.text());
// No need to descend into a method signature;
}
public visitPropertySignature(node: TypeScript.PropertySignatureSyntax): void {
this.createItem(node, TypeScript.Syntax.emptyList<ISyntaxToken>(), ScriptElementKind.memberVariableElement, node.propertyName.text());
this.createItem(node, TypeScript.Syntax.emptyList<ISyntaxToken>(), ts.ScriptElementKind.memberVariableElement, node.propertyName.text());
// No need to descend into a property signature;
}
@ -316,7 +316,7 @@ module TypeScript.Services {
// the parser will synthesize an identifier.
// we shouldn't add an unnamed function declaration
if (width(node.identifier) > 0) {
this.createItem(node, node.modifiers, ScriptElementKind.functionElement, node.identifier.text());
this.createItem(node, node.modifiers, ts.ScriptElementKind.functionElement, node.identifier.text());
}
// No need to descend into a function declaration;

View file

@ -53,17 +53,17 @@ module TypeScript.Services {
"with",
];
private static keywordCompletions: CompletionEntry[] = null;
private static keywordCompletions: ts.CompletionEntry[] = null;
public static getKeywordCompltions(): CompletionEntry[]{
public static getKeywordCompltions(): ts.CompletionEntry[]{
if (KeywordCompletions.keywordCompletions === null) {
var completions: CompletionEntry[] = [];
var completions: ts.CompletionEntry[] = [];
for (var i = 0, n = KeywordCompletions.keywords.length; i < n; i++) {
var keyword = KeywordCompletions.keywords[i];
completions.push({
name: keyword,
kind: ScriptElementKind.keyword,
kindModifiers: ScriptElementKindModifier.none
kind: ts.ScriptElementKind.keyword,
kindModifiers: ts.ScriptElementKindModifier.none
});
}

View file

@ -280,31 +280,6 @@ module ts {
}
}
function initializeServices() {
objectAllocator = {
getNodeConstructor: kind => {
function Node() {
}
var proto = new NodeObject();
proto.kind = kind;
proto.pos = 0;
proto.end = 0;
proto.flags = 0;
proto.parent = undefined;
Node.prototype = proto;
return <any>Node;
},
getSymbolConstructor: () => SymbolObject,
getTypeConstructor: () => TypeObject,
getSignatureConstructor: () => SignatureObject,
};
}
initializeServices();
}
module TypeScript.Services {
export interface Logger {
information(): boolean;
debug(): boolean;
@ -363,7 +338,7 @@ module TypeScript.Services {
getOutliningRegions(fileName: string): TypeScript.TextSpan[];
getBraceMatchingAtPosition(fileName: string, position: number): TypeScript.TextSpan[];
getIndentationAtPosition(fileName: string, position: number, options: TypeScript.Services.EditorOptions): number;
getIndentationAtPosition(fileName: string, position: number, options: EditorOptions): number;
getFormattingEditsForRange(fileName: string, minChar: number, limChar: number, options: FormatCodeOptions): TextEdit[];
getFormattingEditsForDocument(fileName: string, minChar: number, limChar: number, options: FormatCodeOptions): TextEdit[];
@ -431,8 +406,14 @@ module TypeScript.Services {
containerName: string;
}
export interface MemberName {
prefix: string;
suffix: string;
text: string;
}
export interface TypeInfo {
memberName: TypeScript.MemberName;
memberName: MemberName;
docComment: string;
fullSymbolName: string;
kind: string;
@ -564,7 +545,7 @@ module TypeScript.Services {
acquireDocument(
filename: string,
compilationSettings: ts.CompilerOptions,
scriptSnapshot: IScriptSnapshot,
scriptSnapshot: TypeScript.IScriptSnapshot,
byteOrderMark: ts.ByteOrderMark,
version: number,
isOpen: boolean,
@ -574,10 +555,10 @@ module TypeScript.Services {
document: Document,
filename: string,
compilationSettings: ts.CompilerOptions,
scriptSnapshot: IScriptSnapshot,
scriptSnapshot: TypeScript.IScriptSnapshot,
version: number,
isOpen: boolean,
textChangeRange: TextChangeRange
textChangeRange: TypeScript.TextChangeRange
): Document;
releaseDocument(filename: string, compilationSettings: ts.CompilerOptions): void
@ -666,59 +647,52 @@ module TypeScript.Services {
static prefix = "prefix";
}
export class DiagnosticCategory {
static none = "";
static error = "error";
static warning = "warning";
static message = "message";
}
export interface IncrementalParse {
(oldSyntaxTree: SyntaxTree, textChangeRange: TextChangeRange, newText: ISimpleText): SyntaxTree
(oldSyntaxTree: TypeScript.SyntaxTree, textChangeRange: TypeScript.TextChangeRange, newText: TypeScript.ISimpleText): TypeScript.SyntaxTree
}
export class Document {
private _bloomFilter: BloomFilter = null;
private _bloomFilter: TypeScript.BloomFilter = null;
// By default, our Document class doesn't support incremental update of its contents.
// However, we enable other layers (like teh services layer) to inject the capability
// into us by setting this function.
public static incrementalParse: IncrementalParse = IncrementalParser.parse;
public static incrementalParse: IncrementalParse = TypeScript.IncrementalParser.parse;
constructor(private compilationSettings: ts.CompilerOptions,
public filename: string,
public referencedFiles: string[],
private _scriptSnapshot: IScriptSnapshot,
private _scriptSnapshot: TypeScript.IScriptSnapshot,
public byteOrderMark: ts.ByteOrderMark,
public version: number,
public isOpen: boolean,
private _syntaxTree: SyntaxTree,
private _syntaxTree: TypeScript.SyntaxTree,
private _soruceFile: ts.SourceFile) {
}
public isDeclareFile(): boolean {
return isDTSFile(this.filename);
return TypeScript.isDTSFile(this.filename);
}
public sourceUnit(): SourceUnitSyntax {
public sourceUnit(): TypeScript.SourceUnitSyntax {
// If we don't have a script, create one from our parse tree.
return this.syntaxTree().sourceUnit();
}
public diagnostics(): Diagnostic[] {
return this.syntaxTree().diagnostics();
}
//public diagnostics(): Diagnostic[] {
// return this.syntaxTree().diagnostics();
//}
public lineMap(): LineMap {
public lineMap(): TypeScript.LineMap {
return this.syntaxTree().lineMap();
}
public syntaxTree(): SyntaxTree {
public syntaxTree(): TypeScript.SyntaxTree {
if (!this._syntaxTree) {
var start = new Date().getTime();
this._syntaxTree = Parser.parse(
this.filename, SimpleText.fromScriptSnapshot(this._scriptSnapshot), this.compilationSettings.target, this.isDeclareFile());
this._syntaxTree = TypeScript.Parser.parse(
this.filename, TypeScript.SimpleText.fromScriptSnapshot(this._scriptSnapshot), this.compilationSettings.target, this.isDeclareFile());
var time = new Date().getTime() - start;
@ -742,13 +716,13 @@ module TypeScript.Services {
return this._soruceFile;
}
public bloomFilter(): BloomFilter {
public bloomFilter(): TypeScript.BloomFilter {
if (!this._bloomFilter) {
var identifiers = createIntrinsicsObject<boolean>();
var identifiers = TypeScript.createIntrinsicsObject<boolean>();
var pre = function (cur: TypeScript.ISyntaxElement) {
if (ASTHelpers.isValidAstNode(cur)) {
if (cur.kind() === SyntaxKind.IdentifierName) {
var nodeText = tokenValueText((<TypeScript.ISyntaxToken>cur));
if (TypeScript.ASTHelpers.isValidAstNode(cur)) {
if (cur.kind() === TypeScript.SyntaxKind.IdentifierName) {
var nodeText = TypeScript.tokenValueText((<TypeScript.ISyntaxToken>cur));
identifiers[nodeText] = true;
}
@ -764,7 +738,7 @@ module TypeScript.Services {
}
}
this._bloomFilter = new BloomFilter(identifierCount);
this._bloomFilter = new TypeScript.BloomFilter(identifierCount);
this._bloomFilter.addKeys(identifiers);
}
return this._bloomFilter;
@ -780,7 +754,7 @@ module TypeScript.Services {
return !this.compilationSettings.out || this.syntaxTree().isExternalModule();
}
public update(scriptSnapshot: IScriptSnapshot, version: number, isOpen: boolean, textChangeRange: TextChangeRange): Document {
public update(scriptSnapshot: TypeScript.IScriptSnapshot, version: number, isOpen: boolean, textChangeRange: TypeScript.TextChangeRange): Document {
// See if we are currently holding onto a syntax tree. We may not be because we're
// either a closed file, or we've just been lazy and haven't had to create the syntax
// tree yet. Access the field instead of the method so we don't accidently realize
@ -804,7 +778,7 @@ module TypeScript.Services {
}
}
var text = SimpleText.fromScriptSnapshot(scriptSnapshot);
var text = TypeScript.SimpleText.fromScriptSnapshot(scriptSnapshot);
// If we don't have a text change, or we don't have an old syntax tree, then do a full
// parse. Otherwise, do an incremental parse.
@ -815,7 +789,7 @@ module TypeScript.Services {
return new Document(this.compilationSettings, this.filename, this.referencedFiles, scriptSnapshot, this.byteOrderMark, version, isOpen, newSyntaxTree, /*soruceFile*/ null);
}
public static create(compilationSettings: ts.CompilerOptions, fileName: string, scriptSnapshot: IScriptSnapshot, byteOrderMark: ts.ByteOrderMark, version: number, isOpen: boolean, referencedFiles: string[]): Document {
public static create(compilationSettings: ts.CompilerOptions, fileName: string, scriptSnapshot: TypeScript.IScriptSnapshot, byteOrderMark: ts.ByteOrderMark, version: number, isOpen: boolean, referencedFiles: string[]): Document {
return new Document(compilationSettings, fileName, referencedFiles, scriptSnapshot, byteOrderMark, version, isOpen, /*syntaxTree:*/ null, /*soruceFile*/ null);
}
}
@ -1015,7 +989,7 @@ module TypeScript.Services {
return this._currentFileSyntaxTree;
}
public getCurrentScriptSnapshot(filename: string): IScriptSnapshot {
public getCurrentScriptSnapshot(filename: string): TypeScript.IScriptSnapshot {
// update _currentFileScriptSnapshot as a part of 'getCurrentFileSyntaxTree' call
this.getCurrentFileSyntaxTree(filename);
return this._currentFileScriptSnapshot;
@ -1042,8 +1016,8 @@ module TypeScript.Services {
return this.createSyntaxTree(filename, scriptSnapshot);
}
var nextSyntaxTree = IncrementalParser.parse(
previousSyntaxTree, editRange, SimpleText.fromScriptSnapshot(scriptSnapshot));
var nextSyntaxTree = TypeScript.IncrementalParser.parse(
previousSyntaxTree, editRange, TypeScript.SimpleText.fromScriptSnapshot(scriptSnapshot));
this.ensureInvariants(filename, editRange, nextSyntaxTree, this._currentFileScriptSnapshot, scriptSnapshot);
@ -1106,7 +1080,7 @@ module TypeScript.Services {
// Ok, the trees looked good. So at least our incremental parser agrees with the
// normal parser. Now, verify that the incremental tree matches the contents of the
// script snapshot.
var incrementalTreeText = fullText(incrementalTree.sourceUnit());
var incrementalTreeText = TypeScript.fullText(incrementalTree.sourceUnit());
var actualSnapshotText = newScriptSnapshot.getText(0, newScriptSnapshot.getLength());
Debug.assert(incrementalTreeText === actualSnapshotText, 'Expected full texts to be equal');
}
@ -1150,7 +1124,7 @@ module TypeScript.Services {
public acquireDocument(
filename: string,
compilationSettings: ts.CompilerOptions,
scriptSnapshot: IScriptSnapshot,
scriptSnapshot: TypeScript.IScriptSnapshot,
byteOrderMark: ts.ByteOrderMark,
version: number,
isOpen: boolean,
@ -1176,10 +1150,10 @@ module TypeScript.Services {
document: Document,
filename: string,
compilationSettings: ts.CompilerOptions,
scriptSnapshot: IScriptSnapshot,
scriptSnapshot: TypeScript.IScriptSnapshot,
version: number,
isOpen: boolean,
textChangeRange: TextChangeRange
textChangeRange: TypeScript.TextChangeRange
): Document {
var bucket = this.getBucketForCompilationSettings(compilationSettings, /*createIfMissing*/ false);
@ -1211,7 +1185,7 @@ module TypeScript.Services {
export function createLanguageService(host: LanguageServiceHost, documentRegistry: IDocumentRegistry): LanguageService {
var _syntaxTreeCache: SyntaxTreeCache = new SyntaxTreeCache(host);
var formattingRulesProvider: Formatting.RulesProvider;
var formattingRulesProvider: TypeScript.Services.Formatting.RulesProvider;
var hostCache: HostCache; // A cache of all the information about the files on the host side.
var program: ts.Program;
var typeChecker: ts.TypeChecker;
@ -1313,7 +1287,7 @@ module TypeScript.Services {
// file was closed, then we always want to reparse. This is so our tree doesn't keep
// the old buffer alive that represented the file on disk (as the host has moved to a
// new text buffer).
var textChangeRange: TextChangeRange = null;
var textChangeRange: TypeScript.TextChangeRange = null;
if (document.isOpen && isOpen) {
textChangeRange = hostCache.getScriptTextChangeRangeSinceVersion(filename, document.version);
}
@ -1361,7 +1335,7 @@ module TypeScript.Services {
// Try to get a valid display name for this symbol, if we could not find one, then ignore it.
// We would like to only show things that can be added after a dot, so for instance numeric properties can
// not be accessed with a dot (a.1 <- invalid)
var displayName = CompletionHelpers.getValidCompletionEntryDisplayName(symbol.getName(), program.getCompilerOptions().target);
var displayName = TypeScript.Services.CompletionHelpers.getValidCompletionEntryDisplayName(symbol.getName(), program.getCompilerOptions().target);
if (!displayName) {
return undefined;
}
@ -1393,7 +1367,7 @@ module TypeScript.Services {
var document = documentsByName[filename];
var sourceUnit = document.sourceUnit();
if (CompletionHelpers.isCompletionListBlocker(document.syntaxTree().sourceUnit(), position)) {
if (TypeScript.Services.CompletionHelpers.isCompletionListBlocker(document.syntaxTree().sourceUnit(), position)) {
host.log("Returning an empty list because completion was blocked.");
return null;
}
@ -1401,7 +1375,7 @@ module TypeScript.Services {
var node = TypeScript.ASTHelpers.getAstAtPosition(sourceUnit, position, /*useTrailingTriviaAsLimChar*/ true, /*forceInclusive*/ true);
if (node && node.kind() === TypeScript.SyntaxKind.IdentifierName &&
start(node) === end(node)) {
TypeScript.start(node) === TypeScript.end(node)) {
// Ignore missing name nodes
node = node.parent;
}
@ -1409,14 +1383,14 @@ module TypeScript.Services {
var isRightOfDot = false;
if (node &&
node.kind() === TypeScript.SyntaxKind.MemberAccessExpression &&
end((<TypeScript.MemberAccessExpressionSyntax>node).expression) < position) {
TypeScript.end((<TypeScript.MemberAccessExpressionSyntax>node).expression) < position) {
isRightOfDot = true;
node = (<TypeScript.MemberAccessExpressionSyntax>node).expression;
}
else if (node &&
node.kind() === TypeScript.SyntaxKind.QualifiedName &&
end((<TypeScript.QualifiedNameSyntax>node).left) < position) {
TypeScript.end((<TypeScript.QualifiedNameSyntax>node).left) < position) {
isRightOfDot = true;
node = (<TypeScript.QualifiedNameSyntax>node).left;
@ -1439,7 +1413,7 @@ module TypeScript.Services {
}
// TODO: this is a hack for now, we need a proper walking mechanism to verify that we have the correct node
var mappedNode = getNodeAtPosition(document.sourceFile(), end(node) - 1);
var mappedNode = getNodeAtPosition(document.sourceFile(), TypeScript.end(node) - 1);
Debug.assert(mappedNode, "Could not map a Fidelity node to an AST node");
@ -1465,11 +1439,11 @@ module TypeScript.Services {
getCompletionEntriesFromSymbols(symbols, activeCompletionSession);
}
else {
var containingObjectLiteral = CompletionHelpers.getContainingObjectLiteralApplicableForCompletion(document.syntaxTree().sourceUnit(), position);
var containingObjectLiteral = TypeScript.Services.CompletionHelpers.getContainingObjectLiteralApplicableForCompletion(document.syntaxTree().sourceUnit(), position);
// Object literal expression, look up possible property names from contextual type
if (containingObjectLiteral) {
var searchPosition = Math.min(position, end(containingObjectLiteral));
var searchPosition = Math.min(position, TypeScript.end(containingObjectLiteral));
var path = TypeScript.ASTHelpers.getAstAtPosition(sourceUnit, searchPosition);
// Get the object literal node
@ -1511,7 +1485,7 @@ module TypeScript.Services {
// Add keywords if this is not a member completion list
if (!isMemberCompletion) {
Array.prototype.push.apply(activeCompletionSession.entries, KeywordCompletions.getKeywordCompltions());
Array.prototype.push.apply(activeCompletionSession.entries, TypeScript.Services.KeywordCompletions.getKeywordCompltions());
}
return {
@ -1666,7 +1640,7 @@ module TypeScript.Services {
var type = typeChecker.getTypeOfSymbol(symbol);
return {
memberName: new MemberNameString(typeChecker.typeToString(type)),
memberName: new TypeScript.MemberNameString(typeChecker.typeToString(type)),
docComment: "",
fullSymbolName: typeChecker.symbolToString(symbol, getEnclosingDeclaration(node)),
kind: getSymbolKind(symbol),
@ -1682,7 +1656,7 @@ module TypeScript.Services {
var type = typeChecker.getTypeOfExpression(node);
Debug.assert(type, "getTypeAtPosition: Could not find type for node");
return {
memberName: new MemberNameString(""),
memberName: new TypeScript.MemberNameString(""),
docComment: "",
fullSymbolName: typeChecker.typeToString(type, getEnclosingDeclaration(node)),
kind: getTypeKind(type),
@ -1708,7 +1682,7 @@ module TypeScript.Services {
return null;
}
if (ast.kind() === SyntaxKind.ParameterList && ast.parent.kind() === SyntaxKind.CallSignature && ast.parent.parent.kind() === SyntaxKind.ConstructorDeclaration) {
if (ast.kind() === TypeScript.SyntaxKind.ParameterList && ast.parent.kind() === TypeScript.SyntaxKind.CallSignature && ast.parent.parent.kind() === TypeScript.SyntaxKind.ConstructorDeclaration) {
ast = ast.parent.parent;
}
@ -1717,7 +1691,7 @@ module TypeScript.Services {
return null;
case TypeScript.SyntaxKind.ConstructorDeclaration:
var constructorAST = <TypeScript.ConstructorDeclarationSyntax>ast;
if (!isConstructorValidPosition || !(position >= start(constructorAST) && position <= start(constructorAST) + "constructor".length)) {
if (!isConstructorValidPosition || !(position >= TypeScript.start(constructorAST) && position <= TypeScript.start(constructorAST) + "constructor".length)) {
return null;
}
else {
@ -1751,8 +1725,8 @@ module TypeScript.Services {
}
return {
minChar: start(node),
limChar: end(node)
minChar: TypeScript.start(node),
limChar: TypeScript.end(node)
};
}
@ -1768,7 +1742,7 @@ module TypeScript.Services {
filename = TypeScript.switchToForwardSlashes(filename);
var syntaxTree = getSyntaxTree(filename);
var items: NavigateToItem[] = [];
GetScriptLexicalStructureWalker.getListsOfAllScriptLexicalStructure(items, filename, syntaxTree.sourceUnit());
TypeScript.Services.GetScriptLexicalStructureWalker.getListsOfAllScriptLexicalStructure(items, filename, syntaxTree.sourceUnit());
return items;
}
@ -1776,13 +1750,13 @@ module TypeScript.Services {
// doesn't use compiler - no need to synchronize with host
filename = TypeScript.switchToForwardSlashes(filename);
var syntaxTree = getSyntaxTree(filename);
return OutliningElementsCollector.collectElements(syntaxTree.sourceUnit());
return TypeScript.Services.OutliningElementsCollector.collectElements(syntaxTree.sourceUnit());
}
function getBraceMatchingAtPosition(filename: string, position: number) {
filename = TypeScript.switchToForwardSlashes(filename);
var syntaxTree = getSyntaxTree(filename);
return BraceMatcher.getMatchSpans(syntaxTree, position);
return TypeScript.Services.BraceMatcher.getMatchSpans(syntaxTree, position);
}
function getIndentationAtPosition(filename: string, position: number, editorOptions: EditorOptions) {
@ -1793,7 +1767,7 @@ module TypeScript.Services {
var scriptSnapshot = _syntaxTreeCache.getCurrentScriptSnapshot(filename);
var scriptText = TypeScript.SimpleText.fromScriptSnapshot(scriptSnapshot);
var textSnapshot = new TypeScript.Services.Formatting.TextSnapshot(scriptText);
var options = new FormattingOptions(!editorOptions.ConvertTabsToSpaces, editorOptions.TabSize, editorOptions.IndentSize, editorOptions.NewLineCharacter)
var options = new TypeScript.FormattingOptions(!editorOptions.ConvertTabsToSpaces, editorOptions.TabSize, editorOptions.IndentSize, editorOptions.NewLineCharacter)
return TypeScript.Services.Formatting.SingleTokenIndenter.getIndentationAmount(position, syntaxTree.sourceUnit(), textSnapshot, options);
}
@ -1934,10 +1908,10 @@ module TypeScript.Services {
};
var simpleText = TypeScript.SimpleText.fromString(text);
scanner = Scanner.createScanner(ts.ScriptTarget.ES5, simpleText, reportDiagnostic);
scanner = TypeScript.Scanner.createScanner(ts.ScriptTarget.ES5, simpleText, reportDiagnostic);
var lastTokenKind = TypeScript.SyntaxKind.None;
var token: ISyntaxToken = null;
var token: TypeScript.ISyntaxToken = null;
do {
lastDiagnosticKey = null;
@ -1946,18 +1920,18 @@ module TypeScript.Services {
processToken(text, simpleText, offset, token, result);
}
while (token.kind() !== SyntaxKind.EndOfFileToken);
while (token.kind() !== TypeScript.SyntaxKind.EndOfFileToken);
lastDiagnosticKey = null;
return result;
}
function processToken(text: string, simpleText: ISimpleText, offset: number, token: TypeScript.ISyntaxToken, result: ClassificationResult): void {
function processToken(text: string, simpleText: TypeScript.ISimpleText, offset: number, token: TypeScript.ISyntaxToken, result: ClassificationResult): void {
processTriviaList(text, offset, token.leadingTrivia(simpleText), result);
addResult(text, offset, result, width(token), token.kind());
addResult(text, offset, result, TypeScript.width(token), token.kind());
processTriviaList(text, offset, token.trailingTrivia(simpleText), result);
if (fullEnd(token) >= text.length) {
if (TypeScript.fullEnd(token) >= text.length) {
// We're at the end.
if (lastDiagnosticKey === TypeScript.DiagnosticCode.AsteriskSlash_expected) {
result.finalLexState = EndOfLineState.InMultiLineCommentTrivia;
@ -2030,4 +2004,26 @@ module TypeScript.Services {
getClassificationsForLine: getClassificationsForLine
};
}
function initializeServices() {
objectAllocator = {
getNodeConstructor: kind => {
function Node() {
}
var proto = new NodeObject();
proto.kind = kind;
proto.pos = 0;
proto.end = 0;
proto.flags = 0;
proto.parent = undefined;
Node.prototype = proto;
return <any>Node;
},
getSymbolConstructor: () => SymbolObject,
getTypeConstructor: () => TypeObject,
getSignatureConstructor: () => SignatureObject,
};
}
initializeServices();
}

View file

@ -18,7 +18,7 @@
/// <reference path='compiler\pathUtils.ts' />
/// <reference path='compiler\precompile.ts' />
var debugObjectHost = (<any>this);
module TypeScript.Services {
module ts {
export interface ScriptSnapshotShim {
// Get's a portion of the script snapshot specified by [start, end).
getText(start: number, end: number): string;
@ -904,7 +904,7 @@ module TypeScript.Services {
/// TODO: this is used by VS, clean this up on both sides of the interfrace
module Services {
export var TypeScriptServicesFactory = TypeScriptServicesFactory;
module TypeScript.Services {
export var TypeScriptServicesFactory = ts.TypeScriptServicesFactory;
}