-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'damms005-feature/vite-and-devdb'
- Loading branch information
Showing
4 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
import * as vscode from 'vscode'; | ||
import * as fs from 'fs'; | ||
import Helpers from './helpers'; | ||
|
||
export default class ViteProvider implements vscode.CompletionItemProvider { | ||
private viteAssets: Array<string> = []; | ||
|
||
constructor() { | ||
this.loadViteManifest(); | ||
setInterval(() => this.loadViteManifest(), 60000); | ||
} | ||
|
||
provideCompletionItems( | ||
document: vscode.TextDocument, | ||
position: vscode.Position, | ||
token: vscode.CancellationToken, | ||
context: vscode.CompletionContext | ||
): Array<vscode.CompletionItem> { | ||
const completions: Array<vscode.CompletionItem> = []; | ||
const func = Helpers.parseDocumentFunction(document, position); | ||
|
||
if (func === null) { | ||
return completions; | ||
} | ||
|
||
if (func && (Helpers.tags.vite.functions.some((fn: string) => func.function.includes(fn)))) { | ||
for (const asset of this.viteAssets) { | ||
const item = new vscode.CompletionItem(asset, vscode.CompletionItemKind.Value); | ||
item.range = document.getWordRangeAtPosition(position, Helpers.wordMatchRegex); | ||
completions.push(item); | ||
} | ||
} | ||
|
||
return completions; | ||
} | ||
|
||
private loadViteManifest() { | ||
try { | ||
const manifestPath = Helpers.projectPath('public/build/manifest.json'); | ||
if (fs.existsSync(manifestPath)) { | ||
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); | ||
this.viteAssets = Object.keys(manifest); | ||
} | ||
} catch (exception) { | ||
console.error(exception); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters