Skip to content

Commit

Permalink
fix: multiline support for autocompletion
Browse files Browse the repository at this point in the history
  • Loading branch information
nhedger committed Jan 18, 2023
1 parent 5040d8b commit 40e91f2
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/providers/inertiaComponentAutocompletion.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
CompletionList,
Position,
ProviderResult,
Range,
TextDocument,
Uri,
workspace,
Expand All @@ -20,15 +21,19 @@ export class InertiaComponentAutocompletionProvider
document: TextDocument,
position: Position
): ProviderResult<CompletionItem[] | CompletionList<CompletionItem>> {
const lineContentUpToCursor = document
.lineAt(position)
.text.slice(0, position.character);
const lineContentUpToCursor = document.getText(
new Range(position.line - 1, 0, position.line, position.character)
);

// https://regex101.com/r/ETfuvN/1
const renderRegex = /(Inertia::render|inertia)\([\s\s]*["']$/;
//https://regex101.com/r/0eMWiO/1
const routeRegex =
/Route::inertia\([\s\S]*(['"]).+\1[\s\S]*,[\s\S]*['"]$/;

if (
!/(Inertia::render|inertia)\(["']$/.test(lineContentUpToCursor) &&
!/Route::inertia\((['"]).+\1\s*,\s*['"]$/.test(
lineContentUpToCursor
)
!renderRegex.test(lineContentUpToCursor) &&
!routeRegex.test(lineContentUpToCursor)
) {
return undefined;
}
Expand Down

0 comments on commit 40e91f2

Please sign in to comment.