Skip to content

Commit ed73222

Browse files
committed
make completions more powerful and generic
1 parent b074aeb commit ed73222

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

src/main.ts

+12-22
Original file line numberDiff line numberDiff line change
@@ -223,28 +223,18 @@ interface CompletionItem {
223223
}
224224

225225
const textDocumentCompletionResult = (): CompletionItem[] => {
226-
return [
227-
{
228-
label: "l-map",
229-
detail: "l-map",
230-
documentation: "Leaflet L.map component",
231-
},
232-
{
233-
label: "l-tile-layer",
234-
detail: "l-tile-layer",
235-
documentation: "Leaflet L.tileLayer component",
236-
},
237-
{
238-
label: "l-marker",
239-
detail: "l-marker",
240-
documentation: "Leaflet L.marker component",
241-
},
242-
{
243-
label: "l-icon",
244-
detail: "l-icon",
245-
documentation: "Leaflet L.icon component",
246-
},
247-
];
226+
return ELEMENT_DEFINITIONS.map(({ tagName, attributes, documentation }) => {
227+
let dom = parse(`<${tagName}></${tagName}>`)
228+
let el = dom.querySelector(tagName)
229+
attributes.forEach((attribute) => {
230+
el?.setAttribute(attribute.name, attribute.default)
231+
})
232+
return {
233+
label: dom.toString(),
234+
detail: tagName,
235+
documentation,
236+
}
237+
})
248238
};
249239

250240
// Diagnostics

src/schema.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@ interface TypedAttribute {
55
default: string;
66
}
77

8-
type Definition = { tagName: string; attributes: TypedAttribute[] };
8+
type Definition = { tagName: string; attributes: TypedAttribute[], documentation: string };
99

1010
export const ELEMENT_DEFINITIONS: Definition[] = [
1111
{
1212
tagName: "l-map",
13+
documentation: "L.map() custom HTML element.",
1314
attributes: [
1415
{ name: "center", format: "json", default: "[0, 0]" },
1516
{ name: "zoom", format: "number", default: "0" },
1617
],
1718
},
1819
{
1920
tagName: "l-tile-layer",
21+
documentation: "L.tileLayer() custom HTML element.",
2022
attributes: [{ name: "url-template", format: "string", default: "" }],
2123
},
2224
{
2325
tagName: "l-circle",
26+
documentation: "L.circle() custom HTML element.",
2427
attributes: [{ name: "lat-lng", format: "json", default: "[0, 0]" }],
2528
},
2629
];

0 commit comments

Comments
 (0)