8000 Add more test · microsoft/TypeScript@e60e239 · GitHub
[go: up one dir, main page]

Skip to content

Commit e60e239

Browse files
committed
Add more test
1 parent 69871ea commit e60e239

File tree

5 files changed

+104
-66
lines changed

5 files changed

+104
-66
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ namespace ts.projectSystem {
16171617
checkProjectActualFiles(projectService.inferredProjects[1], [file2.path]);
16181618
});
16191619

1620-
it ("loading files with correct priority", () => {
1620+
it("loading files with correct priority", () => {
16211621
const f1 = {
16221622
path: "/a/main.ts",
1623 8000 1623
content: "let x = 1"
@@ -1642,14 +1642,14 @@ namespace ts.projectSystem {
16421642
});
16431643
projectService.openClientFile(f1.path);
16441644
projectService.checkNumberOfProjects({ configuredProjects: 1 });
1645-
checkProjectActualFiles(projectService.configuredProjects[0], [ f1.path ]);
1645+
checkProjectActualFiles(projectService.configuredProjects[0], [f1.path]);
16461646

16471647
projectService.closeClientFile(f1.path);
16481648

16491649
projectService.openClientFile(f2.path);
16501650
projectService.checkNumberOfProjects({ configuredProjects: 1, inferredProjects: 1 });
1651-
checkProjectActualFiles(projectService.configuredProjects[0], [ f1.path ]);
1652-
checkProjectActualFiles(projectService.inferredProjects[0], [ f2.path ]);
1651+
checkProjectActualFiles(projectService.configuredProjects[0], [f1.path]);
1652+
checkProjectActualFiles(projectService.inferredProjects[0], [f2.path]);
16531653
});
16541654

16551655
it("tsconfig script block support", () => {
@@ -1767,7 +1767,7 @@ namespace ts.projectSystem {
17671767
// #3. Ensure no errors when compiler options aren't specified
17681768
const config3 = {
17691769
path: "/a/b/tsconfig.json",
1770-
content: JSON.stringify({ })
1770+
content: JSON.stringify({})
17711771
};
17721772

17731773
host = createServerHost([file1, file2, config3, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
@@ -3267,13 +3267,13 @@ namespace ts.projectSystem {
32673267
assert.equal((<protocol.CompileOnSaveAffectedFileListSingleProject[]>response)[0].projectUsesOutFile, expectedUsesOutFile, "usesOutFile");
32683268
}
32693269

3270-
it ("projectUsesOutFile should not be returned if not set", () => {
3270+
it("projectUsesOutFile should not be returned if not set", () => {
32713271
test({}, /*expectedUsesOutFile*/ false);
32723272
});
3273-
it ("projectUsesOutFile should be true if outFile is set", () => {
3273+
it("projectUsesOutFile should be true if outFile is set", () => {
32743274
test({ outFile: "/a/out.js" }, /*expectedUsesOutFile*/ true);
32753275
});
3276-
it ("projectUsesOutFile should be true if out is set", () => {
3276+
it("projectUsesOutFile should be true if out is set", () => {
32773277
test({ out: "/a/out.js" }, /*expectedUsesOutFile*/ true);
32783278
});
32793279
});
@@ -3311,9 +3311,7 @@ namespace ts.projectSystem {
33113311
assert.isDefined(test2Entry, "should contain 'Test2'");
33123312

33133313
assert.isTrue(test1Entry.hasAction, "should set the 'hasAction' property to true for Test1");
3314-
assert.equal(test1Entry.sourceFileName, file2.path, "should have the correct source file name");
33153314
assert.isUndefined(test2Entry.hasAction, "should not set the 'hasAction' property for Test2");
3316-
assert.isUndefined(test2Entry.sourceFileName, "should not set the 'sourceFileName' property for Test2");
33173315
});
33183316
});
33193317

@@ -3407,7 +3405,7 @@ namespace ts.projectSystem {
34073405
};
34083406
})();
34093407
const host = createServerHost([f1, config]);
3410-
const session = createSession(host, /*typingsInstaller*/ undefined, () => {}, cancellationToken);
3408+
const session = createSession(host, /*typingsInstaller*/ undefined, () => { }, cancellationToken);
34113409
{
34123410
session.executeCommandSeq(<protocol.OpenRequest>{
34133411
command: "open",
@@ -3574,6 +3572,70 @@ namespace ts.projectSystem {
35743572
});
35753573
});
35763574

3575+
describe("completion entry with code actions", () => {
3576+
it("should work for symbols from non-imported modules", () => {
3577+
const moduleFile = {
3578+
path: "/a/b/moduleFile.ts",
3579+
content: `export const guitar = 10;`
3580+
};
3581+
const file1 = {
3582+
path: "/a/b/file2.ts",
3583+
content: ``
3584+
};
3585+
const globalFile = {
3586+
path: "/a/b/globalFile.ts",
3587+
content: `interface Jazz { }`
3588+
};
3589+
const ambientModuleFile = {
3590+
path: "/a/b/ambientModuleFile.ts",
3591+
content:
3592+
`declare module "windyAndWarm" {
3593+
export const chetAtkins = "great";
3594+
}`
3595+
};
3596+
const defaultModuleFile = {
3597+
path: "/a/b/defaultModuleFile.ts",
3598+
content:
3599+
`export default function egyptianElla() { };`
3600+
};
3601+
const configFile = {
3602+
path: "/a/b/tsconfig.json",
3603+
content: "{}"
3604+
};
3605+
3606+
const host = createServerHost([moduleFile, file1, globalFile, ambientModuleFile, defaultModuleFile, configFile]);
3607+
const session = createSession(host);
3608+
const projectService = session.getProjectService();
3609+
projectService.openClientFile(file1.path);
3610+
3611+
checkEntryDetail("guitar", /*hasAction*/ true, `import { guitar } from "./moduleFile";\n\n`);
3612+
checkEntryDetail("Jazz", /*hasAction*/ false);
3613+
checkEntryDetail("chetAtkins", /*hasAction*/ true, `import { chetAtkins } from "windyAndWarm";\n\n`);
3614+
checkEntryDetail("egyptianElla", /*hasAction*/ true, `import egyptianElla from "./defaultModuleFile";\n\n`);
3615+
3616+
function checkEntryDetail(entryName: string, hasAction: boolean, insertString?: string) {
3617+
const request = makeSessionRequest<protocol.CompletionDetailsRequestArgs>(
3618+
CommandNames.CompletionDetails,
3619+
{ entryNames: [entryName], file: file1.path, line: 1, offset: 0, projectFileName: configFile.path });
3620+
const response = session.executeCommand(request).response as protocol.CompletionEntryDetails[];
3621+
assert.isTrue(response.length === 1);
3622+
3623+
const entryDetails = response[0];
3624+
if (!hasAction) {
3625+
assert.isUndefined(entryDetails.codeActions);
3626+
}
3627+
else {
3628+
const action = entryDetails.codeActions[0];
3629+
assert.isTrue(action.changes[0].fileName === file1.path);
3630+
assert.deepEqual(action.changes[0], <protocol.FileCodeEdits>{
3631+
fileName: file1.path,
3632+
textChanges: [{ start: { line: 1, offset: 1 }, end: { line: 1, offset: 1 }, newText: insertString }]
3633+
});
3634+
}
3635+
}
3636+
});
3637+
});
3638+
35773639
describe("maxNodeModuleJsDepth for inferred projects", () => {
35783640
it("should be set to 2 if the project has js root files", () => {
35793641
const file1: FileOrFolder = {

src/server/protocol.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace ts.server.protocol {
1313
/* @internal */
1414
export type CompletionsFull = "completions-full";
1515
export type CompletionDetails = "completionEntryDetails";
16-
export type CommitCompletionWithCodeAction = "commitCompletionWithCodeAction";
1716
export type CompileOnSaveAffectedFileList = "compileOnSaveAffectedFileList";
1817
export type CompileOnSaveEmitFile = "compileOnSaveEmitFile";
1918
export type Configure = "configure";
@@ -1225,20 +1224,6 @@ namespace ts.server.protocol {
12251224
command: CommandTypes.Close;
12261225
}
12271226

1228-
export interface CommitCompletionWithCodeActionRequest extends Request {
1229-
command: CommandTypes.CommitCompletionWithCodeAction;
1230-
arguments: CommitCompletionWithCodeActionRequestArgs;
1231-
}
1232-
1233-
export interface CommitCompletionWithCodeActionRequestArgs extends FileRequestArgs {
1234-
itemName: string;
1235-
sourceFileName: string;
1236-
}
1237-
1238-
export interface CommitCompletionWithCodeActionResponse extends Response {
1239-
body?: CodeAction[];
1240-
}
1241-
12421227
/**
12431228
* Request to obtain the list of files that should be regenerated if target file is recompiled.
12441229
* NOTE: this us query-only operation and does not generate any output on disk.
@@ -1542,11 +1527,6 @@ namespace ts.server.protocol {
15421527
* made to avoid errors. The code action is normally adding an additional import statement.
15431528
*/
15441529
hasAction?: true;
1545-
/**
1546-
* ONLY has value when hasAction = true
1547-
* Used to find the corresponding completion item symbol for additional code actions
1548-
*/
1549-
sourceFileName?: string;
15501530
}
15511531

15521532
/**

src/server/session.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,15 +1139,14 @@ namespace ts.server {
11391139
if (simplifiedResult) {
11401140
return completions.entries.reduce((result: protocol.CompletionEntry[], entry: ts.CompletionEntry) => {
11411141
if (completions.isMemberCompletion || (entry.name.toLowerCase().indexOf(prefix.toLowerCase()) === 0)) {
1142-
const { name, kind, kindModifiers, sortText, replacementSpan, hasAction, sourceFileName } = entry;
1142+
const { name, kind, kindModifiers, sortText, replacementSpan, hasAction } = entry;
11431143
const convertedSpan: protocol.TextSpan =
11441144
replacementSpan ? this.decorateSpan(replacementSpan, scriptInfo) : undefined;
11451145

11461146
const newEntry: protocol.CompletionEntry = { name, kind, kindModifiers, sortText, replacementSpan: convertedSpan };
11471147
// avoid serialization when hasAction = false
11481148
if (hasAction) {
11491149
newEntry.hasAction = true;
1150-
newEntry.sourceFileName = sourceFileName;
11511150
}
11521151
result.push(newEntry);
11531152
}

src/services/codefixes/importFixes.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,6 @@ namespace ts.codefix {
128128
}
129129
}
130130

131-
// export function test(symbol: Symbol, sourceFile: SourceFile): CodeAction[] {
132-
// const moduleSymbols = symbol.parent;
133-
// if (!moduleSymbols) {
134-
// return undefined;
135-
// }
136-
// }
137-
138131
function createCodeAction(
139132
description: DiagnosticMessage,
140133
diagnosticArgs: string[],

0 commit comments

Comments
 (0)
0