Skip to content

Commit 8e68302

Browse files
committed
Load native snippet languages from package.json and adjust completion provider logic to avoid duplication.
1 parent 20d0978 commit 8e68302

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

tools/vscode-extension/src/extension.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ function activate(context) {
1414
return;
1515
}
1616

17+
// Load package.json to get native snippet languages
18+
const packagePath = path.join(__dirname, '..', 'package.json');
19+
let nativeSnippetLanguages = [];
20+
try {
21+
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
22+
nativeSnippetLanguages = packageJson.contributes.snippets.map(s => s.language);
23+
} catch (error) {
24+
console.error('Failed to load package.json for native snippet languages:', error);
25+
// Fallback to empty array - custom provider will handle all languages
26+
}
27+
1728
// Register completion provider for custom file extensions and languages
1829
const provider = vscode.languages.registerCompletionItemProvider(
1930
{ scheme: 'file' },
@@ -29,14 +40,14 @@ function activate(context) {
2940
const fileName = document.fileName;
3041
const languageId = document.languageId;
3142

32-
// Check if current file should have Datastar support
43+
// Only provide custom completions for file extensions or languages not covered by native snippets
3344
const shouldProvideSnippets = enabledLanguages.some(item => {
34-
// If item starts with dot, treat as file extension
45+
// If item starts with dot, treat as file extension (always provide for these)
3546
if (item.startsWith('.')) {
3647
return fileName.endsWith(item);
3748
}
38-
// Otherwise treat as language ID
39-
return languageId === item;
49+
// For language IDs, only provide if not already covered by native snippets
50+
return languageId === item && !nativeSnippetLanguages.includes(item);
4051
});
4152

4253
if (!shouldProvideSnippets) {

0 commit comments

Comments
 (0)