Skip to content

Commit 747d564

Browse files
committed
livewire component autocompletion
1 parent 97d854b commit 747d564

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/extension.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ export function activate(context: vscode.ExtensionContext) {
114114
),
115115
vscode.languages.registerCompletionItemProvider(
116116
LANGUAGES,
117+
vscode.languages.registerCompletionItemProvider(
118+
BLADE_LANGUAGES,
119+
livewireComponentCompletion,
120+
":",
121+
),
117122
vscode.languages.registerCompletionItemProvider(
118123
BLADE_LANGUAGES,
119124
new BladeCompletion(),

src/features/livewireComponent.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,29 @@ export const linkProvider: LinkProvider = (doc: vscode.TextDocument) => {
3838

3939
return Promise.resolve(links);
4040
};
41+
42+
export const completionProvider: vscode.CompletionItemProvider = {
43+
provideCompletionItems(
44+
doc: vscode.TextDocument,
45+
pos: vscode.Position,
46+
): vscode.ProviderResult<vscode.CompletionItem[]> {
47+
const componentPrefix = "<livewire:";
48+
const pathPrefix = "livewire.";
49+
const line = doc.lineAt(pos.line).text;
50+
const linePrefix = line.substring(
51+
pos.character - componentPrefix.length,
52+
pos.character,
53+
);
54+
55+
if (linePrefix !== componentPrefix) {
56+
return undefined;
57+
}
58+
59+
return getViews()
60+
.items.filter((view) => view.key.startsWith(pathPrefix))
61+
.map(
62+
(view) =>
63+
new vscode.CompletionItem(view.key.replace(pathPrefix, "")),
64+
);
65+
},
66+
};

0 commit comments

Comments
 (0)