File tree Expand file tree Collapse file tree 5 files changed +54
-3
lines changed Expand file tree Collapse file tree 5 files changed +54
-3
lines changed Original file line number Diff line number Diff line change 48
48
"type" : " bladeComponent" ,
49
49
"label" : " Blade components" ,
50
50
"features" : [
51
- " link"
51
+ " link" ,
52
+ " completion"
52
53
]
53
54
},
54
55
{
Original file line number Diff line number Diff line change 188
188
"generated" : true ,
189
189
"description" : " Enable linking for Blade components."
190
190
},
191
+ "Laravel.bladeComponent.completion" : {
192
+ "type" : " boolean" ,
193
+ "default" : true ,
194
+ "generated" : true ,
195
+ "description" : " Enable completion for Blade components."
196
+ },
191
197
"Laravel.config.diagnostics" : {
192
198
"type" : " boolean" ,
193
199
"default" : true ,
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ import EloquentCompletion from "./completion/Eloquent";
13
13
import Registry from "./completion/Registry" ;
14
14
import ValidationCompletion from "./completion/Validation" ;
15
15
import { updateDiagnostics } from "./diagnostic/diagnostic" ;
16
+ import { completionProvider as bladeComponentCompletion } from "./features/bladeComponent" ;
17
+ import { completionProvider as livewireComponentCompletion } from "./features/livewireComponent" ;
16
18
import { hoverProviders } from "./hover/HoverProvider" ;
17
19
import { linkProviders } from "./link/LinkProvider" ;
18
20
import { configAffected } from "./support/config" ;
@@ -113,7 +115,11 @@ export function activate(context: vscode.ExtensionContext) {
113
115
...TRIGGER_CHARACTERS . concat ( [ "|" ] ) ,
114
116
) ,
115
117
vscode . languages . registerCompletionItemProvider (
116
- LANGUAGES ,
118
+ BLADE_LANGUAGES ,
119
+ bladeComponentCompletion ,
120
+ "x" ,
121
+ "-" ,
122
+ ) ,
117
123
vscode . languages . registerCompletionItemProvider (
118
124
BLADE_LANGUAGES ,
119
125
livewireComponentCompletion ,
Original file line number Diff line number Diff line change 1
1
import { getViews } from "@src/repositories/views" ;
2
+ import { config } from "@src/support/config" ;
2
3
import { projectPath } from "@src/support/project" ;
3
4
import * as vscode from "vscode" ;
4
5
import { LinkProvider } from ".." ;
@@ -39,3 +40,40 @@ export const linkProvider: LinkProvider = (doc: vscode.TextDocument) => {
39
40
40
41
return Promise . resolve ( links ) ;
41
42
} ;
43
+
44
+ export const completionProvider : vscode . CompletionItemProvider = {
45
+ provideCompletionItems (
46
+ doc : vscode . TextDocument ,
47
+ pos : vscode . Position ,
48
+ ) : vscode . ProviderResult < vscode . CompletionItem [ ] > {
49
+ if ( ! config ( "bladeComponent.completion" , true ) ) {
50
+ return undefined ;
51
+ }
52
+
53
+ const componentPrefixes = [ "x" , "x-" ] ;
54
+ const pathPrefix = "components." ;
55
+ const line = doc . lineAt ( pos . line ) . text ;
56
+
57
+ const match = componentPrefixes . find ( ( prefix ) => {
58
+ const linePrefix = line . substring (
59
+ pos . character - prefix . length ,
60
+ pos . character ,
61
+ ) ;
62
+
63
+ return linePrefix !== prefix ;
64
+ } ) ;
65
+
66
+ if ( ! match ) {
67
+ return undefined ;
68
+ }
69
+
70
+ return getViews ( )
71
+ . items . filter ( ( view ) => view . key . startsWith ( pathPrefix ) )
72
+ . map (
73
+ ( view ) =>
74
+ new vscode . CompletionItem (
75
+ "x-" + view . key . replace ( pathPrefix , "" ) ,
76
+ ) ,
77
+ ) ;
78
+ } ,
79
+ } ;
Original file line number Diff line number Diff line change 1
- export type GeneratedConfigKey = 'appBinding.diagnostics' | 'appBinding.hover' | 'appBinding.link' | 'appBinding.completion' | 'asset.diagnostics' | 'asset.hover' | 'asset.link' | 'asset.completion' | 'auth.diagnostics' | 'auth.hover' | 'auth.link' | 'auth.completion' | 'bladeComponent.link' | 'config.diagnostics' | 'config.hover' | 'config.link' | 'config.completion' | 'controllerAction.diagnostics' | 'controllerAction.hover' | 'controllerAction.link' | 'controllerAction.completion' | 'env.diagnostics' | 'env.hover' | 'env.link' | 'env.completion' | 'inertia.diagnostics' | 'inertia.hover' | 'inertia.link' | 'inertia.completion' | 'livewireComponent.link' | 'livewireComponent.completion' | 'middleware.diagnostics' | 'middleware.hover' | 'middleware.link' | 'middleware.completion' | 'mix.diagnostics' | 'mix.hover' | 'mix.link' | 'mix.completion' | 'paths.link' | 'route.diagnostics' | 'route.hover' | 'route.link' | 'route.completion' | 'translation.diagnostics' | 'translation.hover' | 'translation.link' | 'translation.completion' | 'view.diagnostics' | 'view.hover' | 'view.link' | 'view.completion' ;
1
+ export type GeneratedConfigKey = 'appBinding.diagnostics' | 'appBinding.hover' | 'appBinding.link' | 'appBinding.completion' | 'asset.diagnostics' | 'asset.hover' | 'asset.link' | 'asset.completion' | 'auth.diagnostics' | 'auth.hover' | 'auth.link' | 'auth.completion' | 'bladeComponent.link' | 'bladeComponent.completion' | 'config.diagnostics' | 'config.hover' | 'config.link' | 'config.completion' | 'controllerAction.diagnostics' | 'controllerAction.hover' | 'controllerAction.link' | 'controllerAction.completion' | 'env.diagnostics' | 'env.hover' | 'env.link' | 'env.completion' | 'inertia.diagnostics' | 'inertia.hover' | 'inertia.link' | 'inertia.completion' | 'livewireComponent.link' | 'livewireComponent.completion' | 'middleware.diagnostics' | 'middleware.hover' | 'middleware.link' | 'middleware.completion' | 'mix.diagnostics' | 'mix.hover' | 'mix.link' | 'mix.completion' | 'paths.link' | 'route.diagnostics' | 'route.hover' | 'route.link' | 'route.completion' | 'translation.diagnostics' | 'translation.hover' | 'translation.link' | 'translation.completion' | 'view.diagnostics' | 'view.hover' | 'view.link' | 'view.completion' ;
You can’t perform that action at this time.
0 commit comments