From 9b40613d6f90c82baa93394c941d3bdf927c3808 Mon Sep 17 00:00:00 2001 From: Damilola Olowookere Date: Sat, 30 Nov 2024 20:11:56 +0100 Subject: [PATCH 1/5] Implement Vite provider --- src/ViteProvider.ts | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/ViteProvider.ts diff --git a/src/ViteProvider.ts b/src/ViteProvider.ts new file mode 100644 index 0000000..4fa54c5 --- /dev/null +++ b/src/ViteProvider.ts @@ -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 = []; + + constructor() { + this.loadViteManifest(); + setInterval(() => this.loadViteManifest(), 60000); + } + + provideCompletionItems( + document: vscode.TextDocument, + position: vscode.Position, + token: vscode.CancellationToken, + context: vscode.CompletionContext + ): Array { + const completions: Array = []; + 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); + } + } +} \ No newline at end of file From 0bf6ba0612af4ab9c384455da4fe751d2073569b Mon Sep 17 00:00:00 2001 From: Damilola Olowookere Date: Sat, 30 Nov 2024 20:12:31 +0100 Subject: [PATCH 2/5] Add Vite provider to completion item providers --- src/extension.ts | 2 ++ src/helpers.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/src/extension.ts b/src/extension.ts index 5e16371..3e7904f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -9,6 +9,7 @@ import ViewProvider from "./ViewProvider"; import ConfigProvider from './ConfigProvider'; import TranslationProvider from './TranslationProvider'; import MixProvider from './MixProvider'; +import ViteProvider from './ViteProvider'; import ValidationProvider from './ValidationProvider'; import EnvProvider from './EnvProvider'; import MiddlewareProvider from './MiddlewareProvider'; @@ -40,6 +41,7 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(vscode.languages.registerCompletionItemProvider(LANGUAGES, new ConfigProvider, ...TRIGGER_CHARACTERS)); context.subscriptions.push(vscode.languages.registerCompletionItemProvider(LANGUAGES, new TranslationProvider, ...TRIGGER_CHARACTERS)); context.subscriptions.push(vscode.languages.registerCompletionItemProvider(LANGUAGES, new MixProvider, ...TRIGGER_CHARACTERS)); + context.subscriptions.push(vscode.languages.registerCompletionItemProvider(LANGUAGES, new ViteProvider(), ...TRIGGER_CHARACTERS)); context.subscriptions.push(vscode.languages.registerCompletionItemProvider(LANGUAGES, new ValidationProvider, ...TRIGGER_CHARACTERS.concat(['|']))); context.subscriptions.push(vscode.languages.registerCompletionItemProvider(LANGUAGES, new EnvProvider, ...TRIGGER_CHARACTERS)); context.subscriptions.push(vscode.languages.registerCompletionItemProvider(LANGUAGES, new MiddlewareProvider, ...TRIGGER_CHARACTERS)); diff --git a/src/helpers.ts b/src/helpers.ts index fb3ecea..abb8776 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -20,6 +20,7 @@ export default class Helpers { static tags:any = { config: {classes: ['Config'] , functions: ['config']}, mix: {classes: [] , functions: ['mix']}, + vite: {classes: [] , functions: ['vite', '@vite']}, route: {classes: ['Route'] , functions: ['route', 'signedRoute']}, trans: {classes: ['Lang'] , functions: ['__', 'trans', '@lang']}, validation: {classes: ['Validator'] , functions: ['validate', 'sometimes', 'rules']}, From b8b065bdc50f0041ef17de3621052f82fb12e359 Mon Sep 17 00:00:00 2001 From: Damilola Olowookere Date: Sat, 30 Nov 2024 20:33:23 +0100 Subject: [PATCH 3/5] Suggest DevDb non-intrusively --- src/extension.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/extension.ts b/src/extension.ts index 3e7904f..a3fb31d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -49,6 +49,8 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(vscode.languages.registerCompletionItemProvider(LANGUAGES, new AssetProvider, ...TRIGGER_CHARACTERS)); context.subscriptions.push(vscode.languages.registerCompletionItemProvider(LANGUAGES, new EloquentProvider, ...TRIGGER_CHARACTERS.concat(['>']))); context.subscriptions.push(vscode.languages.registerCompletionItemProvider(LANGUAGES, new BladeProvider, '@')); + + suggestDevDbExtension(context); } } } @@ -86,3 +88,37 @@ function showWelcomeMessage(context: vscode.ExtensionContext) { } } +async function suggestDevDbExtension(context: vscode.ExtensionContext) { + if (context.extensionMode === vscode.ExtensionMode.Development) { + return; + } + + const DEVDB_EXTENSION_ID = 'damms005.devdb'; + const RECOMMENDATION_KEY = 'devdbExtensionRecommendation'; + const isDevDbExtensionInstalled = vscode.extensions.getExtension(DEVDB_EXTENSION_ID) !== undefined; + + if (isDevDbExtensionInstalled) { + return; + } + + const currentTime = Date.now(); + const lastRecommendation = context.globalState.get(RECOMMENDATION_KEY); + const aYearSinceLastRecommendation = lastRecommendation && (((currentTime - lastRecommendation) > 365 * 24 * 60 * 60 * 1000)); + + if (!lastRecommendation || aYearSinceLastRecommendation) { + const selection = await vscode.window.showInformationMessage( + 'Enhance your database workflow with DevDb - a zero-config extension to auto-load and display database records.', + 'Get DevDb', + 'Not Now' + ); + + if (selection === 'Get DevDb') { + vscode.commands.executeCommand( + 'workbench.extensions.installExtension', + DEVDB_EXTENSION_ID + ); + } + + context.globalState.update(RECOMMENDATION_KEY, currentTime); + } +} \ No newline at end of file From c410e3ad615a6d3cd3225a9f43f83eb552bbfefc Mon Sep 17 00:00:00 2001 From: Amir Alizadeh Date: Sun, 1 Dec 2024 00:31:54 +0330 Subject: [PATCH 4/5] Refactor DevDb suggestion to prevent message bomb --- src/extension.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index a3fb31d..58111b7 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -49,8 +49,6 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(vscode.languages.registerCompletionItemProvider(LANGUAGES, new AssetProvider, ...TRIGGER_CHARACTERS)); context.subscriptions.push(vscode.languages.registerCompletionItemProvider(LANGUAGES, new EloquentProvider, ...TRIGGER_CHARACTERS.concat(['>']))); context.subscriptions.push(vscode.languages.registerCompletionItemProvider(LANGUAGES, new BladeProvider, '@')); - - suggestDevDbExtension(context); } } } @@ -71,7 +69,7 @@ function showWelcomeMessage(context: vscode.ExtensionContext) { (previousVersionArray[0] < currentVersionArray[0]) ) ) { - message = "Laravel Extra Intellisense updated to " + currentVersion + " - New feature: Add blade directives autocomplete."; + message = "Laravel Extra Intellisense updated to " + currentVersion + " - New Feature✨ : Add Vite autocompletion support."; } if (message) { vscode.window.showInformationMessage(message, '⭐️ Star on Github', '🐞 Report Bug') @@ -85,16 +83,14 @@ function showWelcomeMessage(context: vscode.ExtensionContext) { } }); context.globalState.update('laravel-extra-intellisense-version', currentVersion); + } else { + suggestDevDbExtension(context); } } async function suggestDevDbExtension(context: vscode.ExtensionContext) { - if (context.extensionMode === vscode.ExtensionMode.Development) { - return; - } - const DEVDB_EXTENSION_ID = 'damms005.devdb'; - const RECOMMENDATION_KEY = 'devdbExtensionRecommendation'; + const RECOMMENDATION_KEY = 'laravel-extra-intellisense-devdb-extension-recommendation'; const isDevDbExtensionInstalled = vscode.extensions.getExtension(DEVDB_EXTENSION_ID) !== undefined; if (isDevDbExtensionInstalled) { @@ -107,14 +103,14 @@ async function suggestDevDbExtension(context: vscode.ExtensionContext) { if (!lastRecommendation || aYearSinceLastRecommendation) { const selection = await vscode.window.showInformationMessage( - 'Enhance your database workflow with DevDb - a zero-config extension to auto-load and display database records.', + 'Laravel Extra Intellisense Recommendation: Enhance your database workflow with DevDb - a zero-config extension to auto-load and display database records.', 'Get DevDb', 'Not Now' ); if (selection === 'Get DevDb') { vscode.commands.executeCommand( - 'workbench.extensions.installExtension', + 'extension.open', DEVDB_EXTENSION_ID ); } From 90959b6c2b58ff4b65920e8f9b10f2f9810cc728 Mon Sep 17 00:00:00 2001 From: Amir Alizadeh Date: Sun, 1 Dec 2024 00:32:06 +0330 Subject: [PATCH 5/5] Update readme --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f78ae5a..c4b1b3a 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This extension provides [Laravel](https://laravel.com/) routes, views and ... au * [Views and variables](#views-and-variables) * [Configs](#configs) * [Translations and translation parameters](#translations-and-translation-parameters) -* [Laravel mix function](#laravel-mix-function) +* [Laravel mix and vite functions](#laravel-mix-and-vite-functions) * [Validation rules](#validation-rules) * [View sections and stacks](#view-sections-and-stacks) * [Env](#env) @@ -29,7 +29,7 @@ This extension provides [Laravel](https://laravel.com/) routes, views and ... au ![Configs](./images/screenshot-config.gif) ### Translations and translation parameters ![Translations](./images/screenshot-trans.gif) -### Laravel mix function +### Laravel mix and vite functions ![Mix](./images/screenshot-mix.gif) ### Validation rules ![Validation rules](./images/screenshot-validation.gif) @@ -189,6 +189,7 @@ Also if you writing any sensitive code in your service providers, disable the ex * [Laravel Blade Snippets](https://marketplace.visualstudio.com/items?itemName=onecentlin.laravel-blade) * [Laravel goto view](https://marketplace.visualstudio.com/items?itemName=codingyu.laravel-goto-view) * [Laravel goto controller](https://marketplace.visualstudio.com/items?itemName=stef-k.laravel-goto-controller) +* [DevDb](https://marketplace.visualstudio.com/items?itemName=damms005.devdb) ## Credits * [PHP parser](https://github.com/glayzzle/php-parser)