Skip to content

Commit 2a753bf

Browse files
committed
2 parents 2522faa + aa67f10 commit 2a753bf

File tree

6 files changed

+81
-15
lines changed

6 files changed

+81
-15
lines changed

generatable.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[
22
{
3-
"type": "appBinding"
3+
"type": "appBinding",
4+
"label": "app bindings"
45
},
56
{
67
"type": "asset"
@@ -12,13 +13,15 @@
1213
"type": "config"
1314
},
1415
{
15-
"type": "controllerAction"
16+
"type": "controllerAction",
17+
"label": "controller actions"
1618
},
1719
{
1820
"type": "env"
1921
},
2022
{
21-
"type": "inertia"
23+
"type": "inertia",
24+
"label": "Inertia"
2225
},
2326
{
2427
"type": "middleware"
@@ -40,5 +43,12 @@
4043
"features": [
4144
"link"
4245
]
46+
},
47+
{
48+
"type": "bladeComponent",
49+
"label": "Blade components",
50+
"features": [
51+
"link"
52+
]
4353
}
4454
]

generate-config.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
foreach ($items as $item) {
1313
$type = $item['type'];
14+
$label = $item['label'] ?? $type;
1415
$features = $item['features'] ?? ['diagnostics', 'hover', 'link', 'completion'];
1516

1617
foreach ($features as $feature) {
@@ -19,9 +20,9 @@
1920
'default' => true,
2021
'generated' => true,
2122
'description' => match($feature) {
22-
'diagnostics' => "Enable diagnostics for {$type}.",
23-
'hover' => "Enable hover information for {$type}.",
24-
'link' => "Enable linking for {$type}.",
23+
'diagnostics' => "Enable diagnostics for {$label}.",
24+
'hover' => "Enable hover information for {$label}.",
25+
'link' => "Enable linking for {$label}.",
2526
default => null,
2627
},
2728
];
@@ -36,10 +37,16 @@
3637

3738
$packageJson['contributes']['configuration']['properties'] = array_merge($customConfig, $config);
3839

39-
file_put_contents(__DIR__ . '/package.json', json_encode($packageJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
40+
file_put_contents(
41+
__DIR__ . '/package.json',
42+
json_encode($packageJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL
43+
);
4044

4145
$keys = array_map(function($key) {
4246
return str_replace('Laravel.', '', $key);
4347
}, array_keys($config));
4448

45-
file_put_contents(__DIR__ . '/src/support/generated-config.ts', "export type GeneratedConfigKey = '" . implode("' | '", $keys) . "';");
49+
file_put_contents(
50+
__DIR__ . '/src/support/generated-config.ts',
51+
"export type GeneratedConfigKey = '" . implode("' | '", $keys) . "';" . PHP_EOL
52+
);

package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,19 @@
114114
"type": "boolean",
115115
"default": true,
116116
"generated": true,
117-
"description": "Enable diagnostics for appBinding."
117+
"description": "Enable diagnostics for app bindings."
118118
},
119119
"Laravel.appBinding.hover": {
120120
"type": "boolean",
121121
"default": true,
122122
"generated": true,
123-
"description": "Enable hover information for appBinding."
123+
"description": "Enable hover information for app bindings."
124124
},
125125
"Laravel.appBinding.link": {
126126
"type": "boolean",
127127
"default": true,
128128
"generated": true,
129-
"description": "Enable linking for appBinding."
129+
"description": "Enable linking for app bindings."
130130
},
131131
"Laravel.appBinding.completion": {
132132
"type": "boolean",
@@ -182,6 +182,12 @@
182182
"generated": true,
183183
"description": null
184184
},
185+
"Laravel.bladeComponent.link": {
186+
"type": "boolean",
187+
"default": true,
188+
"generated": true,
189+
"description": "Enable linking for Blade components."
190+
},
185191
"Laravel.config.diagnostics": {
186192
"type": "boolean",
187193
"default": true,
@@ -210,19 +216,19 @@
210216
"type": "boolean",
211217
"default": true,
212218
"generated": true,
213-
"description": "Enable diagnostics for controllerAction."
219+
"description": "Enable diagnostics for controller actions."
214220
},
215221
"Laravel.controllerAction.hover": {
216222
"type": "boolean",
217223
"default": true,
218224
"generated": true,
219-
"description": "Enable hover information for controllerAction."
225+
"description": "Enable hover information for controller actions."
220226
},
221227
"Laravel.controllerAction.link": {
222228
"type": "boolean",
223229
"default": true,
224230
"generated": true,
225-
"description": "Enable linking for controllerAction."
231+
"description": "Enable linking for controller actions."
226232
},
227233
"Laravel.controllerAction.completion": {
228234
"type": "boolean",

src/features/bladeComponent.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { getViews } from "@src/repositories/views";
2+
import { projectPath } from "@src/support/project";
3+
import * as vscode from "vscode";
4+
import { LinkProvider } from "..";
5+
6+
export const linkProvider: LinkProvider = (doc: vscode.TextDocument) => {
7+
const links: vscode.DocumentLink[] = [];
8+
const text = doc.getText();
9+
const lines = text.split("\n");
10+
const views = getViews().items;
11+
12+
lines.forEach((line, index) => {
13+
const match = line.match(/<\/?(x-[^\s>]+)/);
14+
15+
if (match && match.index !== undefined) {
16+
const componentName = match[1].replace("x-", "");
17+
// Standard component
18+
const viewName = "components." + componentName;
19+
// Index component
20+
const altName = `${viewName}.${componentName}`;
21+
const view = views.find((v) => [viewName, altName].includes(v.key));
22+
23+
if (view) {
24+
links.push(
25+
new vscode.DocumentLink(
26+
new vscode.Range(
27+
new vscode.Position(index, match.index + 1),
28+
new vscode.Position(
29+
index,
30+
match.index + match[0].length,
31+
),
32+
),
33+
vscode.Uri.parse(projectPath(view.path)),
34+
),
35+
);
36+
}
37+
}
38+
});
39+
40+
return Promise.resolve(links);
41+
};

src/link/LinkProvider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { linkProvider as appBinding } from "@src/features/appBinding";
44
import { linkProvider as asset } from "@src/features/asset";
55
import { linkProvider as auth } from "@src/features/auth";
6+
import { linkProvider as bladeComponent } from "@src/features/bladeComponent";
67
import { linkProvider as config } from "@src/features/config";
78
import { linkProvider as controllerAction } from "@src/features/controllerAction";
89
import { linkProvider as env } from "@src/features/env";
@@ -37,6 +38,7 @@ const allProviders: Partial<Record<GeneratedConfigKey, LinkProviderType>> = {
3738
"translation.link": translation,
3839
"view.link": view,
3940
"paths.link": paths,
41+
"bladeComponent.link": bladeComponent,
4042
};
4143

4244
export const linkProviders: DocumentLinkProvider[] = Object.entries(

src/support/generated-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
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' | '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' | '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' | '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' | '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';

0 commit comments

Comments
 (0)