Skip to content

Commit b5473c2

Browse files
committed
feat: added support for getCodeFixes,getCombinedCodeFix, getSupportedCodeFixes,getApplicableRefactors,getEditsForRefactor
1 parent aa20305 commit b5473c2

File tree

9 files changed

+380
-50
lines changed

9 files changed

+380
-50
lines changed

package-lock.json

Lines changed: 23 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/exp.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import createTSServerInstance from './utils/server.js';
22
import {FILES} from "./utils/testconfig.js";
33

4-
const tsServer = createTSServerInstance();
4+
const tsServer = createTSServerInstance(false);
55
await tsServer.init();
66
console.log('server intializeed');
77

@@ -115,7 +115,7 @@ for (let file of FILES) {
115115
const getOutliningSpansResponse = await tsServer.getOutliningSpans(file.getOutliningSpans.fileName);
116116
console.log('getOutliningSpansResponse', JSON.stringify(getOutliningSpansResponse));
117117
const todoCommentsResponse = await tsServer.todoComments(file.todoComments.fileName, file.todoComments.descriptors);
118-
console.log('todoCommentsResponse', JSON.stringify(todoCommentsResponse));
118+
console.log('todoCommentsResponse', JSON.stringify(todoCommentsResponse));
119119

120120
const indentationsResponse = await tsServer.indentation(file.indentation.fileName, file.indentation.line, file.indentation.offset, file.indentation.options);
121121
console.log('indentationsResponse', JSON.stringify(indentationsResponse));
@@ -124,9 +124,29 @@ for (let file of FILES) {
124124
const docCommentTemplateResponse = await tsServer.docCommentTemplate(file.docCommentTemplate.fileName, file.docCommentTemplate.line, file.docCommentTemplate.offset);
125125
console.log('docCommentTemplateResponse', JSON.stringify(docCommentTemplateResponse));
126126

127-
const setCompilerOptionsForInferredProjectsResponse = await tsServer.setCompilerOptionsForInferredProjects(file.setCompilerOptionsForInferredProjects.options, file.setCompilerOptionsForInferredProjects.projectRootPath);
128-
console.log('setCompilerOptionsForInferredProjectsResponse', JSON.stringify(setCompilerOptionsForInferredProjectsResponse));
127+
/*const setCompilerOptionsForInferredProjectsResponse = await tsServer.setCompilerOptionsForInferredProjects(file.setCompilerOptionsForInferredProjects.options, file.setCompilerOptionsForInferredProjects.projectRootPath);
128+
console.log('setCompilerOptionsForInferredProjectsResponse', JSON.stringify(setCompilerOptionsForInferredProjectsResponse));*/
129129

130+
//TODO: Revisit
131+
/* await tsServer.openFile(file.getCodeFixes.fileName);
132+
const getCodeFixesResponse = await tsServer.getCodeFixes(file.getCodeFixes.fileName, file.getCodeFixes.startLine, file.getCodeFixes.endLine, file.getCodeFixes.endLine, file.getCodeFixes.endOffset, file.getCodeFixes.errorCodes);
133+
console.log('getCodeFixesResponse', JSON.stringify(getCodeFixesResponse));*/
130134

135+
// TODO: Revisit as it is used along with getCodeFixes in vscode
136+
/* await tsServer.openFile(file.getCombinedCodeFix.scope.args.file);
137+
const getCombinedCodeFixResponse = await tsServer.getCombinedCodeFix(file.getCombinedCodeFix.fileName, file.getCombinedCodeFix.fixId, file.getCombinedCodeFix.scope);
138+
console.log('getCombinedCodeFixResponse', JSON.stringify(getCombinedCodeFixResponse));*/
139+
140+
const getSupportedCodeFixesResponse = await tsServer.getSupportedCodeFixes(file.getSupportedCodeFixes.file);
141+
console.log('getSupportedCodeFixesResponse', JSON.stringify(getSupportedCodeFixesResponse));
142+
143+
await tsServer.openFile(file.getApplicableRefactors.filePath);
144+
const getApplicableRefactorsResponse = await tsServer.getApplicableRefactors(file.getApplicableRefactors.filePath, file.getApplicableRefactors.line, file.getApplicableRefactors.offset/*, file.getApplicableRefactors.triggerReason, file.getApplicableRefactors.kind, file.getApplicableRefactors.includeInteractiveActions*/);
145+
console.log('getApplicableRefactorsResponse', JSON.stringify(getApplicableRefactorsResponse));
146+
147+
//TODO: Write working use case with editor
148+
await tsServer.openFile(file.getEditsForRefactor.filePath);
149+
const getEditsForRefactorResponse = await tsServer.getEditsForRefactor(file.getEditsForRefactor.filePath, file.getEditsForRefactor.refactor, file.getEditsForRefactor.action, file.getEditsForRefactor.startLine, file.getEditsForRefactor.startOffset, file.getEditsForRefactor.endLine, file.getEditsForRefactor.endOffset, file.getEditsForRefactor.interactiveRefactorArguments);
150+
console.log('getEditsForRefactorResponse', JSON.stringify(getEditsForRefactorResponse));
131151
}
132152
//tsServer.exitServer();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Calculator {
2+
add(a: number, b: number): number {
3+
// This block of code can potentially be refactored into a separate method
4+
const result = a + b;
5+
console.log(`Adding ${a} and ${b} gives ${result}`);
6+
return result;
7+
}
8+
}
9+
10+
const calc = new Calculator();
11+
calc.add(5, 3);

src/test/sample/getCodeFixes.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// file.ts
2+
3+
class Greeter {
4+
constructor(private message: string) {}
5+
6+
// Deliberate syntax error: Missing identifier (error code 1003)
7+
const x;
8+
9+
10+
// Deliberate syntax error: Missing semicolon (error code 1005)
11+
greet() {
12+
x = '1';
13+
console.log(this.message)
14+
}
15+
}
16+
17+
// Correct usage to avoid errors in other parts
18+
const greeter = new Greeter("Hello, world!");
19+
greeter.greet();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Calculator {
2+
// Deliberate error: 'num1' and 'num2' implicitly have an 'any' type.
3+
add(num1, num2) {
4+
return num1 + num2;
5+
}
6+
7+
// Deliberate error: Unused local variable 'unusedVar'.
8+
unusedFunction() {
9+
const unusedVar = "This variable is unused";
10+
console.log("This function does nothing");
11+
}
12+
}
13+
14+
const calc = new Calculator();
15+
console.log(calc.add(5, 10));
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// sample.ts
2+
class Greeter {
3+
greeting: string;
4+
5+
constructor(message: string) {
6+
this.greeting = message;
7+
}
8+
9+
greet() {
10+
// This block of code is a candidate for the "Extract Method" refactoring
11+
const greetingMessage = `Hello, ${this.greeting}`;
12+
console.log(greetingMessage);
13+
return greetingMessage;
14+
}
15+
}
16+
17+
const greeter = new Greeter('world');
18+
greeter.greet();

src/test/sample/sematic.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ function greet(name: string) {
33
console.log('Hello, ' + name);
44
}
55

6-
greet(42); // Intentionally passing a number to cause a semantic error.
6+
let x;
7+
x = 1;
8+
greet(x); // Intentionally passing a number to cause a semantic error.

0 commit comments

Comments
 (0)