feat: php definitions
This commit is contained in:
parent
a2af40e141
commit
eadc96ebef
4 changed files with 115 additions and 40 deletions
|
|
@ -9,6 +9,21 @@ import { AstPath } from "../../util/ast";
|
|||
import { ImportDefinitionsService } from "../ImportDefinitionsService";
|
||||
import { AutocompleteSnippet } from "../ranking";
|
||||
|
||||
function getSyntaxTreeString(
|
||||
node: Parser.SyntaxNode,
|
||||
indent: string = "",
|
||||
): string {
|
||||
let result = "";
|
||||
const nodeInfo = `${node.type} [${node.startPosition.row}:${node.startPosition.column} - ${node.endPosition.row}:${node.endPosition.column}]`;
|
||||
result += `${indent}${nodeInfo}\n`;
|
||||
|
||||
for (const child of node.children) {
|
||||
result += getSyntaxTreeString(child, indent + " ");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export class RootPathContextService {
|
||||
private cache = new LRUCache<string, AutocompleteSnippet[]>({
|
||||
max: 100,
|
||||
|
|
@ -58,12 +73,17 @@ export class RootPathContextService {
|
|||
this.importDefinitionsService.get(filepath);
|
||||
break;
|
||||
default:
|
||||
console.log(getSyntaxTreeString(node));
|
||||
|
||||
query = await getQueryForFile(
|
||||
filepath,
|
||||
`root-path-context-queries/${node.type}`,
|
||||
);
|
||||
break;
|
||||
}
|
||||
const type = node.type;
|
||||
|
||||
debugger;
|
||||
|
||||
if (!query) {
|
||||
return snippets;
|
||||
|
|
@ -115,6 +135,9 @@ export class RootPathContextService {
|
|||
RootPathContextService.TYPES_TO_USE.has(node.type),
|
||||
)) {
|
||||
const key = RootPathContextService.keyFromNode(parentKey, astNode);
|
||||
const type = astNode.type;
|
||||
|
||||
debugger;
|
||||
|
||||
const foundInCache = this.cache.get(key);
|
||||
const newSnippets =
|
||||
|
|
|
|||
|
|
@ -1,49 +1,59 @@
|
|||
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_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.py",
|
||||
language: "Python",
|
||||
cursorPosition: { line: 4, character: 25 },
|
||||
fileName: "file1.php",
|
||||
language: "PHP",
|
||||
cursorPosition: { line: 12, character: 32 },
|
||||
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
|
||||
{ row: 10, column: 26 }, // Person
|
||||
{ row: 10, column: 44 }, // Address
|
||||
],
|
||||
},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace BaseNamespace;
|
||||
|
||||
use BaseNamespace\BaseClass;
|
||||
use BaseNamespace\Interfaces\FirstInterface;
|
||||
use BaseNamespace\Interfaces\SecondInterface;
|
||||
use BaseNamespace\Person;
|
||||
use BaseNamespace\Address;
|
||||
|
||||
function getAddress(Person $person): Address
|
||||
{
|
||||
return $person->getAddress();
|
||||
}
|
||||
|
||||
class Group extends BaseClass implements FirstInterface, SecondInterface
|
||||
{
|
||||
private array $people;
|
||||
|
||||
public function __construct(array $people)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->people = $people;
|
||||
}
|
||||
|
||||
public function getPersonAddress(Person $person): Address
|
||||
{
|
||||
return getAddress($person);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
(
|
||||
(function_definition
|
||||
parameters: (formal_parameters
|
||||
(simple_parameter
|
||||
type: (named_type) @param_type
|
||||
)*
|
||||
)
|
||||
return_type: (named_type) @return_type
|
||||
)
|
||||
)
|
||||
Loading…
Add table
Reference in a new issue