Consolidated normalizing slashes to use from typescript core in services
This commit is contained in:
parent
62f1144518
commit
45e4e16afc
|
@ -16,20 +16,6 @@
|
|||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export function stripStartAndEndQuotes(str: string) {
|
||||
var firstCharCode = str && str.charCodeAt(0);
|
||||
if (str && str.length >= 2 && firstCharCode === str.charCodeAt(str.length - 1) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) {
|
||||
return str.substring(1, str.length - 1);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
var switchToForwardSlashesRegEx = /\\/g;
|
||||
export function switchToForwardSlashes(path: string) {
|
||||
return path.replace(switchToForwardSlashesRegEx, "/");
|
||||
}
|
||||
|
||||
function isFileOfExtension(fname: string, ext: string) {
|
||||
var invariantFname = fname.toLocaleUpperCase();
|
||||
var invariantExt = ext.toLocaleUpperCase();
|
||||
|
@ -40,34 +26,4 @@ module TypeScript {
|
|||
export function isDTSFile(fname: string) {
|
||||
return isFileOfExtension(fname, ".d.ts");
|
||||
}
|
||||
|
||||
export function getPathComponents(path: string) {
|
||||
return path.split("/");
|
||||
}
|
||||
|
||||
var normalizePathRegEx = /^\\\\[^\\]/;
|
||||
export function normalizePath(path: string): string {
|
||||
// If it's a UNC style path (i.e. \\server\share), convert to a URI style (i.e. file://server/share)
|
||||
if (normalizePathRegEx.test(path)) {
|
||||
path = "file:" + path;
|
||||
}
|
||||
var parts = getPathComponents(switchToForwardSlashes(path));
|
||||
var normalizedParts: string[] = [];
|
||||
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
var part = parts[i];
|
||||
if (part === ".") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (normalizedParts.length > 0 && ArrayUtilities.last(normalizedParts) !== ".." && part === "..") {
|
||||
normalizedParts.pop();
|
||||
continue;
|
||||
}
|
||||
|
||||
normalizedParts.push(part);
|
||||
}
|
||||
|
||||
return normalizedParts.join("/");
|
||||
}
|
||||
}
|
|
@ -1529,7 +1529,7 @@ module ts {
|
|||
var filenames = host.getScriptFileNames();
|
||||
for (var i = 0, n = filenames.length; i < n; i++) {
|
||||
var filename = filenames[i];
|
||||
this.filenameToEntry[switchToForwardSlashes(filename)] = {
|
||||
this.filenameToEntry[normalizeSlashes(filename)] = {
|
||||
filename: filename,
|
||||
version: host.getScriptVersion(filename),
|
||||
isOpen: host.getScriptIsOpen(filename)
|
||||
|
@ -1544,7 +1544,7 @@ module ts {
|
|||
}
|
||||
|
||||
public getEntry(filename: string): HostFileInformation {
|
||||
filename = switchToForwardSlashes(filename);
|
||||
filename = normalizeSlashes(filename);
|
||||
return lookUp(this.filenameToEntry, filename);
|
||||
}
|
||||
|
||||
|
@ -2322,7 +2322,7 @@ module ts {
|
|||
function getSyntacticDiagnostics(filename: string) {
|
||||
synchronizeHostData();
|
||||
|
||||
filename = switchToForwardSlashes(filename);
|
||||
filename = normalizeSlashes(filename);
|
||||
|
||||
return program.getDiagnostics(getSourceFile(filename).getSourceFile());
|
||||
}
|
||||
|
@ -2334,7 +2334,7 @@ module ts {
|
|||
function getSemanticDiagnostics(filename: string) {
|
||||
synchronizeHostData();
|
||||
|
||||
filename = switchToForwardSlashes(filename)
|
||||
filename = normalizeSlashes(filename)
|
||||
var compilerOptions = program.getCompilerOptions();
|
||||
var checker = getFullTypeCheckChecker();
|
||||
var targetSourceFile = getSourceFile(filename);
|
||||
|
@ -2415,7 +2415,7 @@ module ts {
|
|||
function getCompletionsAtPosition(filename: string, position: number, isMemberCompletion: boolean) {
|
||||
synchronizeHostData();
|
||||
|
||||
filename = switchToForwardSlashes(filename);
|
||||
filename = normalizeSlashes(filename);
|
||||
|
||||
var syntacticStart = new Date().getTime();
|
||||
var sourceFile = getSourceFile(filename);
|
||||
|
@ -2760,7 +2760,7 @@ module ts {
|
|||
function getCompletionEntryDetails(filename: string, position: number, entryName: string): CompletionEntryDetails {
|
||||
// Note: No need to call synchronizeHostData, as we have captured all the data we need
|
||||
// in the getCompletionsAtPosition earlier
|
||||
filename = switchToForwardSlashes(filename);
|
||||
filename = normalizeSlashes(filename);
|
||||
|
||||
var sourceFile = getSourceFile(filename);
|
||||
|
||||
|
@ -3260,7 +3260,7 @@ module ts {
|
|||
function getQuickInfoAtPosition(fileName: string, position: number): QuickInfo {
|
||||
synchronizeHostData();
|
||||
|
||||
fileName = switchToForwardSlashes(fileName);
|
||||
fileName = normalizeSlashes(fileName);
|
||||
var sourceFile = getSourceFile(fileName);
|
||||
var node = getTouchingPropertyName(sourceFile, position);
|
||||
if (!node) {
|
||||
|
@ -3362,7 +3362,7 @@ module ts {
|
|||
|
||||
synchronizeHostData();
|
||||
|
||||
filename = switchToForwardSlashes(filename);
|
||||
filename = normalizeSlashes(filename);
|
||||
var sourceFile = getSourceFile(filename);
|
||||
|
||||
var node = getTouchingPropertyName(sourceFile, position);
|
||||
|
@ -3426,7 +3426,7 @@ module ts {
|
|||
function getOccurrencesAtPosition(filename: string, position: number): ReferenceEntry[] {
|
||||
synchronizeHostData();
|
||||
|
||||
filename = switchToForwardSlashes(filename);
|
||||
filename = normalizeSlashes(filename);
|
||||
var sourceFile = getSourceFile(filename);
|
||||
|
||||
var node = getTouchingWord(sourceFile, position);
|
||||
|
@ -3876,7 +3876,7 @@ module ts {
|
|||
function findReferences(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): ReferenceEntry[] {
|
||||
synchronizeHostData();
|
||||
|
||||
fileName = switchToForwardSlashes(fileName);
|
||||
fileName = normalizeSlashes(fileName);
|
||||
var sourceFile = getSourceFile(fileName);
|
||||
|
||||
var node = getTouchingPropertyName(sourceFile, position);
|
||||
|
@ -4597,7 +4597,7 @@ module ts {
|
|||
|
||||
function getEmitOutput(filename: string): EmitOutput {
|
||||
synchronizeHostData();
|
||||
filename = switchToForwardSlashes(filename);
|
||||
filename = normalizeSlashes(filename);
|
||||
var compilerOptions = program.getCompilerOptions();
|
||||
var targetSourceFile = program.getSourceFile(filename); // Current selected file to be output
|
||||
// If --out flag is not specified, shouldEmitToOwnFile is true. Otherwise shouldEmitToOwnFile is false.
|
||||
|
@ -4771,7 +4771,7 @@ module ts {
|
|||
function getSignatureHelpItems(fileName: string, position: number): SignatureHelpItems {
|
||||
synchronizeHostData();
|
||||
|
||||
fileName = switchToForwardSlashes(fileName);
|
||||
fileName = normalizeSlashes(fileName);
|
||||
var sourceFile = getSourceFile(fileName);
|
||||
|
||||
return SignatureHelp.getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken);
|
||||
|
@ -4841,12 +4841,12 @@ module ts {
|
|||
|
||||
/// Syntactic features
|
||||
function getSyntaxTree(filename: string): TypeScript.SyntaxTree {
|
||||
filename = switchToForwardSlashes(filename);
|
||||
filename = normalizeSlashes(filename);
|
||||
return syntaxTreeCache.getCurrentFileSyntaxTree(filename);
|
||||
}
|
||||
|
||||
function getCurrentSourceFile(filename: string): SourceFile {
|
||||
filename = switchToForwardSlashes(filename);
|
||||
filename = normalizeSlashes(filename);
|
||||
var currentSourceFile = syntaxTreeCache.getCurrentSourceFile(filename);
|
||||
return currentSourceFile;
|
||||
}
|
||||
|
@ -4913,14 +4913,14 @@ module ts {
|
|||
}
|
||||
|
||||
function getNavigationBarItems(filename: string): NavigationBarItem[] {
|
||||
filename = switchToForwardSlashes(filename);
|
||||
filename = normalizeSlashes(filename);
|
||||
|
||||
return NavigationBar.getNavigationBarItems(getCurrentSourceFile(filename));
|
||||
}
|
||||
|
||||
function getSemanticClassifications(fileName: string, span: TypeScript.TextSpan): ClassifiedSpan[] {
|
||||
synchronizeHostData();
|
||||
fileName = switchToForwardSlashes(fileName);
|
||||
fileName = normalizeSlashes(fileName);
|
||||
|
||||
var sourceFile = getSourceFile(fileName);
|
||||
|
||||
|
@ -4991,7 +4991,7 @@ module ts {
|
|||
|
||||
function getSyntacticClassifications(fileName: string, span: TypeScript.TextSpan): ClassifiedSpan[] {
|
||||
// doesn't use compiler - no need to synchronize with host
|
||||
fileName = switchToForwardSlashes(fileName);
|
||||
fileName = normalizeSlashes(fileName);
|
||||
var sourceFile = getCurrentSourceFile(fileName);
|
||||
|
||||
var result: ClassifiedSpan[] = [];
|
||||
|
@ -5121,7 +5121,7 @@ module ts {
|
|||
|
||||
function getOutliningSpans(filename: string): OutliningSpan[] {
|
||||
// doesn't use compiler - no need to synchronize with host
|
||||
filename = switchToForwardSlashes(filename);
|
||||
filename = normalizeSlashes(filename);
|
||||
var sourceFile = getCurrentSourceFile(filename);
|
||||
return OutliningElementsCollector.collectElements(sourceFile);
|
||||
}
|
||||
|
@ -5180,7 +5180,7 @@ module ts {
|
|||
}
|
||||
|
||||
function getIndentationAtPosition(filename: string, position: number, editorOptions: EditorOptions) {
|
||||
filename = switchToForwardSlashes(filename);
|
||||
filename = normalizeSlashes(filename);
|
||||
|
||||
var start = new Date().getTime();
|
||||
var sourceFile = getCurrentSourceFile(filename);
|
||||
|
@ -5217,21 +5217,21 @@ module ts {
|
|||
}
|
||||
|
||||
function getFormattingEditsForRange(fileName: string, start: number, end: number, options: FormatCodeOptions): TextChange[] {
|
||||
fileName = switchToForwardSlashes(fileName);
|
||||
fileName = normalizeSlashes(fileName);
|
||||
|
||||
var manager = getFormattingManager(fileName, options);
|
||||
return manager.formatSelection(start, end);
|
||||
}
|
||||
|
||||
function getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions): TextChange[] {
|
||||
fileName = switchToForwardSlashes(fileName);
|
||||
fileName = normalizeSlashes(fileName);
|
||||
|
||||
var manager = getFormattingManager(fileName, options);
|
||||
return manager.formatDocument();
|
||||
}
|
||||
|
||||
function getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextChange[] {
|
||||
fileName = switchToForwardSlashes(fileName);
|
||||
fileName = normalizeSlashes(fileName);
|
||||
|
||||
var manager = getFormattingManager(fileName, options);
|
||||
|
||||
|
@ -5257,7 +5257,7 @@ module ts {
|
|||
// anything away.
|
||||
synchronizeHostData();
|
||||
|
||||
filename = TypeScript.switchToForwardSlashes(filename);
|
||||
filename = normalizeSlashes(filename);
|
||||
|
||||
var sourceFile = getSourceFile(filename);
|
||||
|
||||
|
@ -5417,7 +5417,7 @@ module ts {
|
|||
function getRenameInfo(fileName: string, position: number): RenameInfo {
|
||||
synchronizeHostData();
|
||||
|
||||
fileName = switchToForwardSlashes(fileName);
|
||||
fileName = normalizeSlashes(fileName);
|
||||
var sourceFile = getSourceFile(fileName);
|
||||
|
||||
var node = getTouchingWord(sourceFile, position);
|
||||
|
|
|
@ -858,7 +858,7 @@ module ts {
|
|||
|
||||
forEach(result.referencedFiles, refFile => {
|
||||
convertResult.referencedFiles.push({
|
||||
path: switchToForwardSlashes(normalizePath(refFile.filename)),
|
||||
path: normalizePath(refFile.filename),
|
||||
position: refFile.pos,
|
||||
length: refFile.end - refFile.pos
|
||||
});
|
||||
|
@ -866,7 +866,7 @@ module ts {
|
|||
|
||||
forEach(result.importedFiles, importedFile => {
|
||||
convertResult.importedFiles.push({
|
||||
path: switchToForwardSlashes(importedFile.filename),
|
||||
path: normalizeSlashes(importedFile.filename),
|
||||
position: importedFile.pos,
|
||||
length: importedFile.end - importedFile.pos
|
||||
});
|
||||
|
|
|
@ -259,10 +259,6 @@ module ts {
|
|||
return n.kind === SyntaxKind.StringLiteral || n.kind === SyntaxKind.NumericLiteral || isWord(n);
|
||||
}
|
||||
|
||||
export var switchToForwardSlashesRegEx = /\\/g;
|
||||
export function switchToForwardSlashes(path: string) {
|
||||
return path.replace(switchToForwardSlashesRegEx, "/");
|
||||
}
|
||||
export function isComment(n: Node): boolean {
|
||||
return n.kind === SyntaxKind.SingleLineCommentTrivia || n.kind === SyntaxKind.MultiLineCommentTrivia;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue