Skip to content

Commit c37060a

Browse files
committed
Remove getCurrentSourceFile and use syntaxTreeCache.getCurrentSourceFile instead
1 parent c2c7b90 commit c37060a

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/services/services.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4844,13 +4844,15 @@ module ts {
48444844
}
48454845

48464846
/// Syntactic features
4847-
function getCurrentSourceFile(fileName: string): SourceFile {
4847+
function getSourceFile(fileName: string): SourceFile {
48484848
return syntaxTreeCache.getCurrentSourceFile(fileName);
48494849
}
48504850

48514851
function getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): TextSpan {
4852+
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
4853+
48524854
// Get node at the location
4853-
var node = getTouchingPropertyName(getCurrentSourceFile(fileName), startPos);
4855+
var node = getTouchingPropertyName(sourceFile, startPos);
48544856

48554857
if (!node) {
48564858
return;
@@ -4904,11 +4906,15 @@ module ts {
49044906

49054907
function getBreakpointStatementAtPosition(fileName: string, position: number) {
49064908
// doesn't use compiler - no need to synchronize with host
4907-
return BreakpointResolver.spanInSourceFileAtLocation(getCurrentSourceFile(fileName), position);
4909+
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
4910+
4911+
return BreakpointResolver.spanInSourceFileAtLocation(sourceFile, position);
49084912
}
49094913

4910-
function getNavigationBarItems(fileName: string): NavigationBarItem[] {
4911-
return NavigationBar.getNavigationBarItems(getCurrentSourceFile(fileName));
4914+
function getNavigationBarItems(fileName: string): NavigationBarItem[]{
4915+
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
4916+
4917+
return NavigationBar.getNavigationBarItems(sourceFile);
49124918
}
49134919

49144920
function getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[] {
@@ -4986,7 +4992,7 @@ module ts {
49864992

49874993
function getSyntacticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[] {
49884994
// doesn't use compiler - no need to synchronize with host
4989-
var sourceFile = getCurrentSourceFile(fileName);
4995+
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
49904996

49914997
// Make a scanner we can get trivia from.
49924998
var triviaScanner = createScanner(ScriptTarget.Latest, /*skipTrivia:*/ false, sourceFile.text);
@@ -5204,12 +5210,12 @@ module ts {
52045210

52055211
function getOutliningSpans(fileName: string): OutliningSpan[] {
52065212
// doesn't use compiler - no need to synchronize with host
5207-
var sourceFile = getCurrentSourceFile(fileName);
5213+
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
52085214
return OutliningElementsCollector.collectElements(sourceFile);
52095215
}
52105216

52115217
function getBraceMatchingAtPosition(fileName: string, position: number) {
5212-
var sourceFile = getCurrentSourceFile(fileName);
5218+
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
52135219
var result: TextSpan[] = [];
52145220

52155221
var token = getTouchingToken(sourceFile, position);
@@ -5263,7 +5269,7 @@ module ts {
52635269

52645270
function getIndentationAtPosition(fileName: string, position: number, editorOptions: EditorOptions) {
52655271
var start = new Date().getTime();
5266-
var sourceFile = getCurrentSourceFile(fileName);
5272+
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
52675273
log("getIndentationAtPosition: getCurrentSourceFile: " + (new Date().getTime() - start));
52685274

52695275
var start = new Date().getTime();
@@ -5275,17 +5281,17 @@ module ts {
52755281
}
52765282

52775283
function getFormattingEditsForRange(fileName: string, start: number, end: number, options: FormatCodeOptions): TextChange[] {
5278-
var sourceFile = getCurrentSourceFile(fileName);
5284+
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
52795285
return formatting.formatSelection(start, end, sourceFile, getRuleProvider(options), options);
52805286
}
52815287

52825288
function getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions): TextChange[] {
5283-
var sourceFile = getCurrentSourceFile(fileName);
5289+
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
52845290
return formatting.formatDocument(sourceFile, getRuleProvider(options), options);
52855291
}
52865292

52875293
function getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextChange[] {
5288-
var sourceFile = getCurrentSourceFile(fileName);
5294+
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
52895295

52905296
if (key === "}") {
52915297
return formatting.formatOnClosingCurly(position, sourceFile, getRuleProvider(options), options);
@@ -5539,7 +5545,7 @@ module ts {
55395545
getFormattingEditsForDocument,
55405546
getFormattingEditsAfterKeystroke,
55415547
getEmitOutput,
5542-
getSourceFile: getCurrentSourceFile,
5548+
getSourceFile,
55435549
getProgram
55445550
};
55455551
}

0 commit comments

Comments
 (0)