Skip to content

Commit 698af70

Browse files
committed
auto complete + link blade index components
1 parent 1ba85c6 commit 698af70

File tree

1 file changed

+40
-21
lines changed

1 file changed

+40
-21
lines changed

src/features/bladeComponent.ts

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,30 @@ export const linkProvider: LinkProvider = (doc: vscode.TextDocument) => {
1818
// Standard component
1919
const viewName = "components." + componentName;
2020
// Index component
21-
const altName = `${viewName}.${componentName}`;
22-
const view = views.find((v) => [viewName, altName].includes(v.key));
23-
24-
if (view) {
25-
links.push(
26-
new vscode.DocumentLink(
27-
new vscode.Range(
28-
new vscode.Position(index, match.index + 1),
29-
new vscode.Position(
30-
index,
31-
match.index + match[0].length,
32-
),
21+
const indexName = `${viewName}.index`;
22+
// Index component (via same name)
23+
const sameIndexName = `${viewName}.${componentName.split(".").pop()}`;
24+
25+
const view = views.find((v) =>
26+
[viewName, indexName, sameIndexName].includes(v.key),
27+
);
28+
29+
if (!view) {
30+
return;
31+
}
32+
33+
links.push(
34+
new vscode.DocumentLink(
35+
new vscode.Range(
36+
new vscode.Position(index, match.index + 1),
37+
new vscode.Position(
38+
index,
39+
match.index + match[0].length,
3340
),
34-
vscode.Uri.parse(projectPath(view.path)),
3541
),
36-
);
37-
}
42+
vscode.Uri.parse(projectPath(view.path)),
43+
),
44+
);
3845
}
3946
});
4047

@@ -69,11 +76,23 @@ export const completionProvider: vscode.CompletionItemProvider = {
6976

7077
return getViews()
7178
.items.filter((view) => view.key.startsWith(pathPrefix))
72-
.map(
73-
(view) =>
74-
new vscode.CompletionItem(
75-
"x-" + view.key.replace(pathPrefix, ""),
76-
),
77-
);
79+
.map((view) => {
80+
const parts = view.key.split(".");
81+
82+
if (parts[parts.length - 1] === "index") {
83+
parts.pop();
84+
}
85+
86+
while (
87+
parts.length > 1 &&
88+
parts[parts.length - 1] === parts[parts.length - 2]
89+
) {
90+
parts.pop();
91+
}
92+
93+
return new vscode.CompletionItem(
94+
"x-" + parts.join(".").replace(pathPrefix, ""),
95+
);
96+
});
7897
},
7998
};

0 commit comments

Comments
 (0)