feat: php definitions

This commit is contained in:
tomasz-io 2024-11-13 10:23:37 -08:00
parent eadc96ebef
commit 8da703f745
4 changed files with 87 additions and 51 deletions

View file

@ -43,6 +43,7 @@ export class RootPathContextService {
"function_declaration",
"function_definition",
"method_definition",
"method_declaration",
"class_declaration",
"class_definition",
]);
@ -73,7 +74,9 @@ export class RootPathContextService {
this.importDefinitionsService.get(filepath);
break;
default:
console.log(getSyntaxTreeString(node));
// const type = node.type;
// debugger;
// console.log(getSyntaxTreeString(node));
query = await getQueryForFile(
filepath,
@ -83,8 +86,6 @@ export class RootPathContextService {
}
const type = node.type;
debugger;
if (!query) {
return snippets;
}
@ -135,9 +136,8 @@ export class RootPathContextService {
RootPathContextService.TYPES_TO_USE.has(node.type),
)) {
const key = RootPathContextService.keyFromNode(parentKey, astNode);
const type = astNode.type;
debugger;
// const type = astNode.type;
// debugger;
const foundInCache = this.cache.get(key);
const newSnippets =

View file

@ -1,51 +1,51 @@
import { testRootPathContext } from "./testUtils";
const TEST_CASES = [
// {
// nodeType: "function_declaration",
// fileName: "file1.ts",
// language: "TypeScript",
// cursorPosition: { line: 10, character: 24 },
// definitionPositions: [
// { row: 9, column: 34 }, // Person
// { row: 9, column: 44 }, // Address
// ],
// },
// {
// nodeType: "method_declaration",
// fileName: "file1.ts",
// language: "TypeScript",
// cursorPosition: { line: 22, character: 30 },
// definitionPositions: [
// { 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
// ],
// },
// {
// nodeType: "function_definition",
// fileName: "file1.py",
// language: "Python",
// cursorPosition: { line: 4, character: 25 },
// definitionPositions: [
// { row: 3, column: 30 }, // Person
// { row: 3, column: 42 }, // Address
// ],
// },
// {
// nodeType: "function_definition (inside a class)",
// fileName: "file1.py",
// language: "Python",
// cursorPosition: { line: 12, character: 33 },
// definitionPositions: [
// { row: 6, column: 21 }, // BaseClass
// { row: 6, column: 33 }, // Collection
// { row: 11, column: 47 }, // Person
// { row: 11, column: 59 }, // Address
// ],
// },
{
nodeType: "function_declaration",
fileName: "file1.ts",
language: "TypeScript",
cursorPosition: { line: 10, character: 24 },
definitionPositions: [
{ row: 9, column: 34 }, // Person
{ row: 9, column: 44 }, // Address
],
},
{
nodeType: "method_declaration",
fileName: "file1.ts",
language: "TypeScript",
cursorPosition: { line: 22, character: 30 },
definitionPositions: [
{ 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
],
},
{
nodeType: "function_definition",
fileName: "file1.py",
language: "Python",
cursorPosition: { line: 4, character: 25 },
definitionPositions: [
{ row: 3, column: 30 }, // Person
{ row: 3, column: 42 }, // Address
],
},
{
nodeType: "function_definition (inside a class)",
fileName: "file1.py",
language: "Python",
cursorPosition: { line: 12, character: 33 },
definitionPositions: [
{ row: 6, column: 21 }, // BaseClass
{ row: 6, column: 33 }, // Collection
{ row: 11, column: 47 }, // Person
{ row: 11, column: 59 }, // Address
],
},
{
nodeType: "function_definition",
fileName: "file1.php",
@ -56,6 +56,19 @@ const TEST_CASES = [
{ row: 10, column: 44 }, // Address
],
},
{
nodeType: "function_definition (inside a class)",
fileName: "file1.php",
language: "PHP",
cursorPosition: { line: 26, character: 35 },
definitionPositions: [
{ row: 15, column: 29 }, // BaseClass
{ row: 15, column: 55 }, // FirstInterface
{ row: 15, column: 72 }, // SecondInterface
{ row: 25, column: 43 }, // Person
{ row: 25, column: 61 }, // Address
],
},
];
describe("RootPathContextService", () => {

View file

@ -0,0 +1,13 @@
(
(class_declaration
(base_clause
(name) @superclass)
)
)
(
(class_declaration
(class_interface_clause
(name) @interface)
)
)

View file

@ -0,0 +1,10 @@
(
(method_declaration
(formal_parameters
(simple_parameter
type: (named_type) @param_type
)*
)
return_type: (named_type) @return_type
)
)