From 2035db1d51b0eaae1d840ceba1a70541a77153c3 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Fri, 23 Sep 2016 17:37:11 -0700 Subject: [PATCH 01/27] Convert to Doc Comment --- src/services/types.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/services/types.ts b/src/services/types.ts index e8c411cc1c8..35d52532687 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -473,7 +473,11 @@ namespace ts { export interface CompletionInfo { isMemberCompletion: boolean; - isNewIdentifierLocation: boolean; // true when the current location also allows for a new identifier + + /** + * true when the current location also allows for a new identifier + */ + isNewIdentifierLocation: boolean; entries: CompletionEntry[]; } From b38d7ac9fd41c46b70c0e5fcfe815a25c98270a4 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Mon, 26 Sep 2016 11:19:06 -0700 Subject: [PATCH 02/27] Annotate directorySeparator --- src/compiler/core.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 72d05e1cfd7..aca9701eee7 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1044,9 +1044,14 @@ namespace ts { return 0; } + /** + * Internally, we represent paths as strings with '/' as the directory separator. + * When we make system calls (eg: LanguageServiceHost.getDirectory()), + * we expect the host to correctly handle paths in our specified format. + */ export const directorySeparator = "/"; const directorySeparatorCharCode = CharacterCodes.slash; - function getNormalizedParts(normalizedSlashedPath: string, rootLength: number) { + function getNormalizedParts(normalizedSlashedPath: string, rootLength: number): string[] { const parts = normalizedSlashedPath.substr(rootLength).split(directorySeparator); const normalized: string[] = []; for (const part of parts) { From d423aadc72c5247db5f674f7277429bcf39fc6af Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Mon, 26 Sep 2016 13:34:07 -0700 Subject: [PATCH 03/27] comments --- src/services/completions.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/services/completions.ts b/src/services/completions.ts index d6a4da89ed1..00a5f80379b 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -323,12 +323,12 @@ namespace ts.Completions { } function getCompletionEntriesForDirectoryFragment(fragment: string, scriptPath: string, extensions: string[], includeExtensions: boolean, span: TextSpan, exclude?: string, result: CompletionEntry[] = []): CompletionEntry[] { - fragment = getDirectoryPath(fragment); + fragment = getDirectoryPath(fragment); // TODO: modify fragment so it respects our internal path representation? if (!fragment) { - fragment = "./"; + fragment = "." + directorySeparator; } else { - fragment = ensureTrailingDirectorySeparator(fragment); + fragment = ensureTrailingDirectorySeparator(fragment); // TODO: why is this necessary? } const absolutePath = normalizeAndPreserveTrailingSlash(isRootedDiskPath(fragment) ? fragment : combinePaths(scriptPath, fragment)); @@ -544,7 +544,7 @@ namespace ts.Completions { const kind = match[2]; const toComplete = match[3]; - const scriptPath = getDirectoryPath(sourceFile.path); + const scriptPath = getDirectoryPath(sourceFile.path); // TODO: normalize for win10? let entries: CompletionEntry[]; if (kind === "path") { // Give completions for a relative path From 1f7b6e6a31afaaa00a57cf875b7a3a41af267250 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Tue, 27 Sep 2016 10:54:03 -0700 Subject: [PATCH 04/27] More comments --- src/compiler/core.ts | 11 +++++++++-- src/services/completions.ts | 14 +++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index aca9701eee7..0b6dd3c9d7c 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1015,7 +1015,9 @@ namespace ts { return path.replace(/\\/g, "/"); } - // Returns length of path root (i.e. length of "/", "x:/", "//server/share/, file:///user/files") + /** + * 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; @@ -1074,7 +1076,7 @@ namespace ts { export function normalizePath(path: string): string { path = normalizeSlashes(path); - const rootLength = getRootLength(path); + const rootLength = getRootLength(path); // TODO: this expects un-slash-normalized strings. eg: 'x:\\...' const root = path.substr(0, rootLength); const normalized = getNormalizedParts(path, rootLength); if (normalized.length) { @@ -1091,6 +1093,11 @@ namespace ts { return path.charCodeAt(path.length - 1) === directorySeparatorCharCode; } + /** + * Returns the path except for its basename. Eg: + * + * /path/to/file.ext -> /path/to + */ export function getDirectoryPath(path: Path): Path; export function getDirectoryPath(path: string): string; export function getDirectoryPath(path: string): any { diff --git a/src/services/completions.ts b/src/services/completions.ts index 00a5f80379b..04b68544376 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -322,10 +322,22 @@ namespace ts.Completions { return result; } + /** + * Given a path ending at a directory, gets the completions for the path. + */ function getCompletionEntriesForDirectoryFragment(fragment: string, scriptPath: string, extensions: string[], includeExtensions: boolean, span: TextSpan, exclude?: string, result: CompletionEntry[] = []): CompletionEntry[] { + /*Debug.assert(fragment !== undefined); + + if (fragment === "") { + fragment = "."; + } else { + fragment = getDirectoryPath(fragment); + } + */ + fragment = getDirectoryPath(fragment); // TODO: modify fragment so it respects our internal path representation? if (!fragment) { - fragment = "." + directorySeparator; + fragment = "."; } else { fragment = ensureTrailingDirectorySeparator(fragment); // TODO: why is this necessary? From 769d248519c28bc538ee9eedf657d9fbacf3f354 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Tue, 27 Sep 2016 13:43:42 -0700 Subject: [PATCH 05/27] new test --- .../tripleSlashRefPathRelativePaths.ts | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 tests/cases/fourslash/tripleSlashRefPathRelativePaths.ts diff --git a/tests/cases/fourslash/tripleSlashRefPathRelativePaths.ts b/tests/cases/fourslash/tripleSlashRefPathRelativePaths.ts new file mode 100644 index 00000000000..96d0a11214f --- /dev/null +++ b/tests/cases/fourslash/tripleSlashRefPathRelativePaths.ts @@ -0,0 +1,137 @@ +/// + +// Exercises relative path completions going up and down 2 directories +// and the use of forward- and back-slashes and combinations thereof. + +// @Filename: f1.ts +//// /*f1*/ +// @Filename: f2.ts +//// /*f2*/ +// @Filename: dir1/g1.ts +//// /*g1*/ +// @Filename: dir1/g2.ts +//// /*g2*/ +// @Filename: dir1/dir2/h1.ts +//// /*h1*/ +// @Filename: dir1/dir2/h2.ts +//// /*h2*/ +// @Filename: dir1/dir2/.hidden.ts +//// /*hidden*/ +// @Filename: dir1/dir2/dir3/i1.ts +//// /*i1*/ +// @Filename: dir1/dir2/dir3/i2.ts +//// /*i2*/ +// @Filename: dir1/dir2/dir3/dir4/j1.ts +//// /*j1*/ +// @Filename: dir1/dir2/dir3/dir4/j2.ts +//// /*j2*/ + + +// @Filename: dir1/dir2/test.ts +//// /// Date: Tue, 27 Sep 2016 14:04:57 -0700 Subject: [PATCH 06/27] remove Comment --- src/services/completions.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/services/completions.ts b/src/services/completions.ts index 04b68544376..35a7bce5561 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -326,18 +326,9 @@ namespace ts.Completions { * Given a path ending at a directory, gets the completions for the path. */ function getCompletionEntriesForDirectoryFragment(fragment: string, scriptPath: string, extensions: string[], includeExtensions: boolean, span: TextSpan, exclude?: string, result: CompletionEntry[] = []): CompletionEntry[] { - /*Debug.assert(fragment !== undefined); - - if (fragment === "") { - fragment = "."; - } else { - fragment = getDirectoryPath(fragment); - } - */ - fragment = getDirectoryPath(fragment); // TODO: modify fragment so it respects our internal path representation? if (!fragment) { - fragment = "."; + fragment = "./"; } else { fragment = ensureTrailingDirectorySeparator(fragment); // TODO: why is this necessary? From 629e126718d7a6950e0394082fdd7964bdc4857f Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Wed, 28 Sep 2016 16:04:39 -0700 Subject: [PATCH 07/27] Factored out hidden path test --- .../fourslash/tripleSlashRefPathHiddenFile.ts | 28 +++++++++++++++++++ .../tripleSlashRefPathRelativePaths.ts | 8 ++---- 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 tests/cases/fourslash/tripleSlashRefPathHiddenFile.ts diff --git a/tests/cases/fourslash/tripleSlashRefPathHiddenFile.ts b/tests/cases/fourslash/tripleSlashRefPathHiddenFile.ts new file mode 100644 index 00000000000..6c1280637e9 --- /dev/null +++ b/tests/cases/fourslash/tripleSlashRefPathHiddenFile.ts @@ -0,0 +1,28 @@ +/// + +// Exercises completions for hidden files (ie: those beginning with '.') + +// @Filename: f1.ts +//// /*f1*/ +// @Filename: f2.ts +//// /*f2*/ +// @Filename: .hidden.ts +//// /*hidden*/ + +// @Filename: test.ts +//// /// Date: Wed, 28 Sep 2016 16:45:52 -0700 Subject: [PATCH 08/27] factor and simplify rel path test --- .../tripleSlashRefPathBackandForwardSlash.ts | 73 +++++++++ .../tripleSlashRefPathCompletionsNarrow.ts | 21 +++ .../fourslash/tripleSlashRefPathHiddenFile.ts | 9 +- .../tripleSlashRefPathRelativePaths.ts | 143 ++++++------------ 4 files changed, 145 insertions(+), 101 deletions(-) create mode 100644 tests/cases/fourslash/tripleSlashRefPathBackandForwardSlash.ts create mode 100644 tests/cases/fourslash/tripleSlashRefPathCompletionsNarrow.ts diff --git a/tests/cases/fourslash/tripleSlashRefPathBackandForwardSlash.ts b/tests/cases/fourslash/tripleSlashRefPathBackandForwardSlash.ts new file mode 100644 index 00000000000..c7cae3c4a45 --- /dev/null +++ b/tests/cases/fourslash/tripleSlashRefPathBackandForwardSlash.ts @@ -0,0 +1,73 @@ +/// + +// Exercises completions for hidden files (ie: those beginning with '.') + +// @Filename: f.ts +//// /*f1*/ +// @Filename: d1/g.ts +//// /*g1*/ +// @Filename: d1/d2/h.ts +//// /*h1*/ +// @Filename: d1/d2/d3/i.ts +//// /// + +// Exercises relative path completions going up and down 2 directories +// and the use of forward- and back-slashes and combinations thereof. + +// @Filename: f1.ts +//// /*f1*/ +// @Filename: f2.ts +//// /*f2*/ + +// @Filename: test.ts +//// ///