feat: capture base class and interfaces implemented
This commit is contained in:
parent
da62797415
commit
df2bbc89da
5 changed files with 66 additions and 36 deletions
|
|
@ -25,6 +25,7 @@ export class RootPathContextService {
|
|||
"program",
|
||||
"function_declaration",
|
||||
"method_definition",
|
||||
"class_declaration",
|
||||
]);
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,29 +1,42 @@
|
|||
import { testRootPathContext } from "./testUtils";
|
||||
|
||||
const TEST_CASES = [
|
||||
{
|
||||
description: "function",
|
||||
fileName: "file1.ts",
|
||||
range: {
|
||||
start: { line: 10, character: 2 },
|
||||
end: { line: 10, character: 24 },
|
||||
},
|
||||
positions: [
|
||||
{ row: 9, column: 34 }, // Person
|
||||
{ row: 9, column: 44 }, // Address
|
||||
],
|
||||
},
|
||||
{
|
||||
description: "class method",
|
||||
fileName: "file1.ts",
|
||||
range: {
|
||||
start: { line: 22, character: 4 },
|
||||
end: { line: 22, character: 30 },
|
||||
},
|
||||
positions: [
|
||||
{ row: 13, column: 29 }, // BaseClass
|
||||
{ row: 13, column: 55 }, // FirstInterface
|
||||
{ row: 13, column: 72 }, // SecondInterface
|
||||
{ row: 21, column: 33 }, // Person
|
||||
{ row: 21, column: 43 }, // Address
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
describe("RootPathContextService", () => {
|
||||
describe("TypeScript should return expected snippets when editing inside a:", () => {
|
||||
test("function", async () => {
|
||||
await testRootPathContext(
|
||||
"typescript",
|
||||
"file1.ts",
|
||||
{ start: { line: 3, character: 2 }, end: { line: 3, character: 24 } },
|
||||
[
|
||||
{ row: 2, column: 34 },
|
||||
{ row: 2, column: 44 },
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
test("class method", async () => {
|
||||
await testRootPathContext(
|
||||
"typescript",
|
||||
"file1.ts",
|
||||
{ start: { line: 14, character: 4 }, end: { line: 14, character: 30 } },
|
||||
[
|
||||
{ row: 13, column: 33 },
|
||||
{ row: 13, column: 43 },
|
||||
],
|
||||
);
|
||||
});
|
||||
test.each(TEST_CASES)(
|
||||
"should look for correct type definitions when editing inside a $description",
|
||||
async ({ fileName, range, positions }) => {
|
||||
await testRootPathContext("typescript", fileName, range, positions);
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,13 +1,21 @@
|
|||
import { Address, Person } from "./types";
|
||||
import {
|
||||
Address,
|
||||
Person,
|
||||
BaseClass,
|
||||
FirstInterface,
|
||||
SecondInterface,
|
||||
// @ts-ignore
|
||||
} from "./types";
|
||||
|
||||
function getAddress(person: Person): Address {
|
||||
return person.address;
|
||||
}
|
||||
|
||||
class Group {
|
||||
class Group extends BaseClass implements FirstInterface, SecondInterface {
|
||||
people: Person[];
|
||||
|
||||
constructor(people: Person[]) {
|
||||
super();
|
||||
this.people = people;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
export interface Person {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
age: number;
|
||||
address: Address;
|
||||
}
|
||||
|
||||
export interface Address {
|
||||
street: string;
|
||||
city: string;
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
(
|
||||
(class_declaration
|
||||
(class_heritage
|
||||
(extends_clause
|
||||
(identifier) @base-class
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(
|
||||
(class_declaration
|
||||
(class_heritage
|
||||
(implements_clause
|
||||
(type_identifier) @interface
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
Loading…
Add table
Reference in a new issue