Skip to content

Commit 45e4e16

Browse files
committed
Consolidated normalizing slashes to use from typescript core in services
1 parent 62f1144 commit 45e4e16

File tree

4 files changed

+26
-74
lines changed

4 files changed

+26
-74
lines changed

src/services/compiler/pathUtils.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@
1616
///<reference path='references.ts' />
1717

1818
module TypeScript {
19-
export function stripStartAndEndQuotes(str: string) {
20-
var firstCharCode = str && str.charCodeAt(0);
21-
if (str && str.length >= 2 && firstCharCode === str.charCodeAt(str.length - 1) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) {
22-
return str.substring(1, str.length - 1);
23-
}
24-
25-
return str;
26-
}
27-
28-
var switchToForwardSlashesRegEx = /\\/g;
29-
export function switchToForwardSlashes(path: string) {
30-
return path.replace(switchToForwardSlashesRegEx, "/");
31-
}
32-
3319
function isFileOfExtension(fname: string, ext: string) {
3420
var invariantFname = fname.toLocaleUpperCase();
3521
var invariantExt = ext.toLocaleUpperCase();
@@ -40,34 +26,4 @@ module TypeScript {
4026
export function isDTSFile(fname: string) {
4127
return isFileOfExtension(fname, ".d.ts");
4228
}
43-
44-
export function getPathComponents(path: string) {
45-
return path.split("/");
46-
}
47-
48-
var normalizePathRegEx = /^\\\\[^\\]/;
49-
export function normalizePath(path: string): string {
50-
// If it's a UNC style path (i.e. \\server\share), convert to a URI style (i.e. file://server/share)
51-
if (normalizePathRegEx.test(path)) {
52-
path = "file:" + path;
53-
}
54-
var parts = getPathComponents(switchToForwardSlashes(path));
55-
var normalizedParts: string[] = [];
56-
57-
for (var i = 0; i < parts.length; i++) {
58-
var part = parts[i];
59-
if (part === ".") {
60-
continue;
61-
}
62-
63-
if (normalizedParts.length > 0 && ArrayUtilities.last(normalizedParts) !== ".." && part === "..") {
64-
normalizedParts.pop();
65-
continue;
66-
}
67-
68-
normalizedParts.push(part);
69-
}
70-
71-
return normalizedParts.join("/");
72-
}
7329
}

src/services/services.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ module ts {
15291529
var filenames = host.getScriptFileNames();
15301530
for (var i = 0, n = filenames.length; i < n; i++) {
15311531
var filename = filenames[i];
1532-
this.filenameToEntry[switchToForwardSlashes(filename)] = {
1532+
this.filenameToEntry[normalizeSlashes(filename)] = {
15331533
filename: filename,
15341534
version: host.getScriptVersion(filename),
15351535
isOpen: host.getScriptIsOpen(filename)
@@ -1544,7 +1544,7 @@ module ts {
15441544
}
15451545

15461546
public getEntry(filename: string): HostFileInformation {
1547-
filename = switchToForwardSlashes(filename);
1547+
filename = normalizeSlashes(filename);
15481548
return lookUp(this.filenameToEntry, filename);
15491549
}
15501550

@@ -2322,7 +2322,7 @@ module ts {
23222322
function getSyntacticDiagnostics(filename: string) {
23232323
synchronizeHostData();
23242324

2325-
filename = switchToForwardSlashes(filename);
2325+
filename = normalizeSlashes(filename);
23262326

23272327
return program.getDiagnostics(getSourceFile(filename).getSourceFile());
23282328
}
@@ -2334,7 +2334,7 @@ module ts {
23342334
function getSemanticDiagnostics(filename: string) {
23352335
synchronizeHostData();
23362336

2337-
filename = switchToForwardSlashes(filename)
2337+
filename = normalizeSlashes(filename)
23382338
var compilerOptions = program.getCompilerOptions();
23392339
var checker = getFullTypeCheckChecker();
23402340
var targetSourceFile = getSourceFile(filename);
@@ -2415,7 +2415,7 @@ module ts {
24152415
function getCompletionsAtPosition(filename: string, position: number, isMemberCompletion: boolean) {
24162416
synchronizeHostData();
24172417

2418-
filename = switchToForwardSlashes(filename);
2418+
filename = normalizeSlashes(filename);
24192419

24202420
var syntacticStart = new Date().getTime();
24212421
var sourceFile = getSourceFile(filename);
@@ -2760,7 +2760,7 @@ module ts {
27602760
function getCompletionEntryDetails(filename: string, position: number, entryName: string): CompletionEntryDetails {
27612761
// Note: No need to call synchronizeHostData, as we have captured all the data we need
27622762
// in the getCompletionsAtPosition earlier
2763-
filename = switchToForwardSlashes(filename);
2763+
filename = normalizeSlashes(filename);
27642764

27652765
var sourceFile = getSourceFile(filename);
27662766

@@ -3260,7 +3260,7 @@ module ts {
32603260
function getQuickInfoAtPosition(fileName: string, position: number): QuickInfo {
32613261
synchronizeHostData();
32623262

3263-
fileName = switchToForwardSlashes(fileName);
3263+
fileName = normalizeSlashes(fileName);
32643264
var sourceFile = getSourceFile(fileName);
32653265
var node = getTouchingPropertyName(sourceFile, position);
32663266
if (!node) {
@@ -3362,7 +3362,7 @@ module ts {
33623362

33633363
synchronizeHostData();
33643364

3365-
filename = switchToForwardSlashes(filename);
3365+
filename = normalizeSlashes(filename);
33663366
var sourceFile = getSourceFile(filename);
33673367

33683368
var node = getTouchingPropertyName(sourceFile, position);
@@ -3426,7 +3426,7 @@ module ts {
34263426
function getOccurrencesAtPosition(filename: string, position: number): ReferenceEntry[] {
34273427
synchronizeHostData();
34283428

3429-
filename = switchToForwardSlashes(filename);
3429+
filename = normalizeSlashes(filename);
34303430
var sourceFile = getSourceFile(filename);
34313431

34323432
var node = getTouchingWord(sourceFile, position);
@@ -3876,7 +3876,7 @@ module ts {
38763876
function findReferences(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): ReferenceEntry[] {
38773877
synchronizeHostData();
38783878

3879-
fileName = switchToForwardSlashes(fileName);
3879+
fileName = normalizeSlashes(fileName);
38803880
var sourceFile = getSourceFile(fileName);
38813881

38823882
var node = getTouchingPropertyName(sourceFile, position);
@@ -4597,7 +4597,7 @@ module ts {
45974597

45984598
function getEmitOutput(filename: string): EmitOutput {
45994599
synchronizeHostData();
4600-
filename = switchToForwardSlashes(filename);
4600+
filename = normalizeSlashes(filename);
46014601
var compilerOptions = program.getCompilerOptions();
46024602
var targetSourceFile = program.getSourceFile(filename); // Current selected file to be output
46034603
// If --out flag is not specified, shouldEmitToOwnFile is true. Otherwise shouldEmitToOwnFile is false.
@@ -4771,7 +4771,7 @@ module ts {
47714771
function getSignatureHelpItems(fileName: string, position: number): SignatureHelpItems {
47724772
synchronizeHostData();
47734773

4774-
fileName = switchToForwardSlashes(fileName);
4774+
fileName = normalizeSlashes(fileName);
47754775
var sourceFile = getSourceFile(fileName);
47764776

47774777
return SignatureHelp.getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken);
@@ -4841,12 +4841,12 @@ module ts {
48414841

48424842
/// Syntactic features
48434843
function getSyntaxTree(filename: string): TypeScript.SyntaxTree {
4844-
filename = switchToForwardSlashes(filename);
4844+
filename = normalizeSlashes(filename);
48454845
return syntaxTreeCache.getCurrentFileSyntaxTree(filename);
48464846
}
48474847

48484848
function getCurrentSourceFile(filename: string): SourceFile {
4849-
filename = switchToForwardSlashes(filename);
4849+
filename = normalizeSlashes(filename);
48504850
var currentSourceFile = syntaxTreeCache.getCurrentSourceFile(filename);
48514851
return currentSourceFile;
48524852
}
@@ -4913,14 +4913,14 @@ module ts {
49134913
}
49144914

49154915
function getNavigationBarItems(filename: string): NavigationBarItem[] {
4916-
filename = switchToForwardSlashes(filename);
4916+
filename = normalizeSlashes(filename);
49174917

49184918
return NavigationBar.getNavigationBarItems(getCurrentSourceFile(filename));
49194919
}
49204920

49214921
function getSemanticClassifications(fileName: string, span: TypeScript.TextSpan): ClassifiedSpan[] {
49224922
synchronizeHostData();
4923-
fileName = switchToForwardSlashes(fileName);
4923+
fileName = normalizeSlashes(fileName);
49244924

49254925
var sourceFile = getSourceFile(fileName);
49264926

@@ -4991,7 +4991,7 @@ module ts {
49914991

49924992
function getSyntacticClassifications(fileName: string, span: TypeScript.TextSpan): ClassifiedSpan[] {
49934993
// doesn't use compiler - no need to synchronize with host
4994-
fileName = switchToForwardSlashes(fileName);
4994+
fileName = normalizeSlashes(fileName);
49954995
var sourceFile = getCurrentSourceFile(fileName);
49964996

49974997
var result: ClassifiedSpan[] = [];
@@ -5121,7 +5121,7 @@ module ts {
51215121

51225122
function getOutliningSpans(filename: string): OutliningSpan[] {
51235123
// doesn't use compiler - no need to synchronize with host
5124-
filename = switchToForwardSlashes(filename);
5124+
filename = normalizeSlashes(filename);
51255125
var sourceFile = getCurrentSourceFile(filename);
51265126
return OutliningElementsCollector.collectElements(sourceFile);
51275127
}
@@ -5180,7 +5180,7 @@ module ts {
51805180
}
51815181

51825182
function getIndentationAtPosition(filename: string, position: number, editorOptions: EditorOptions) {
5183-
filename = switchToForwardSlashes(filename);
5183+
filename = normalizeSlashes(filename);
51845184

51855185
var start = new Date().getTime();
51865186
var sourceFile = getCurrentSourceFile(filename);
@@ -5217,21 +5217,21 @@ module ts {
52175217
}
52185218

52195219
function getFormattingEditsForRange(fileName: string, start: number, end: number, options: FormatCodeOptions): TextChange[] {
5220-
fileName = switchToForwardSlashes(fileName);
5220+
fileName = normalizeSlashes(fileName);
52215221

52225222
var manager = getFormattingManager(fileName, options);
52235223
return manager.formatSelection(start, end);
52245224
}
52255225

52265226
function getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions): TextChange[] {
5227-
fileName = switchToForwardSlashes(fileName);
5227+
fileName = normalizeSlashes(fileName);
52285228

52295229
var manager = getFormattingManager(fileName, options);
52305230
return manager.formatDocument();
52315231
}
52325232

52335233
function getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextChange[] {
5234-
fileName = switchToForwardSlashes(fileName);
5234+
fileName = normalizeSlashes(fileName);
52355235

52365236
var manager = getFormattingManager(fileName, options);
52375237

@@ -5257,7 +5257,7 @@ module ts {
52575257
// anything away.
52585258
synchronizeHostData();
52595259

5260-
filename = TypeScript.switchToForwardSlashes(filename);
5260+
filename = normalizeSlashes(filename);
52615261

52625262
var sourceFile = getSourceFile(filename);
52635263

@@ -5417,7 +5417,7 @@ module ts {
54175417
function getRenameInfo(fileName: string, position: number): RenameInfo {
54185418
synchronizeHostData();
54195419

5420-
fileName = switchToForwardSlashes(fileName);
5420+
fileName = normalizeSlashes(fileName);
54215421
var sourceFile = getSourceFile(fileName);
54225422

54235423
var node = getTouchingWord(sourceFile, position);

src/services/shims.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,15 +858,15 @@ module ts {
858858

859859
forEach(result.referencedFiles, refFile => {
860860
convertResult.referencedFiles.push({
861-
path: switchToForwardSlashes(normalizePath(refFile.filename)),
861+
path: normalizePath(refFile.filename),
862862
position: refFile.pos,
863863
length: refFile.end - refFile.pos
864864
});
865865
});
866866

867867
forEach(result.importedFiles, importedFile => {
868868
convertResult.importedFiles.push({
869-
path: switchToForwardSlashes(importedFile.filename),
869+
path: normalizeSlashes(importedFile.filename),
870870
position: importedFile.pos,
871871
length: importedFile.end - importedFile.pos
872872
});

src/services/utilities.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,6 @@ module ts {
259259
return n.kind === SyntaxKind.StringLiteral || n.kind === SyntaxKind.NumericLiteral || isWord(n);
260260
}
261261

262-
export var switchToForwardSlashesRegEx = /\\/g;
263-
export function switchToForwardSlashes(path: string) {
264-
return path.replace(switchToForwardSlashesRegEx, "/");
265-
}
266262
export function isComment(n: Node): boolean {
267263
return n.kind === SyntaxKind.SingleLineCommentTrivia || n.kind === SyntaxKind.MultiLineCommentTrivia;
268264
}

0 commit comments

Comments
 (0)