Skip to content

Commit

Permalink
fix: recover vueBase, not following file configuration (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
adhamfarrag authored Sep 19, 2024
1 parent bf60b86 commit 317a3c8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ While using the CLI directly from your terminal is perfectly viable, Nuxtr's int

**Nuxt Snippets**: Enhance your development speed with Nuxt snippets. Simply type `nuxt` for components, `use` for Composables, or begin typing Nuxt utilities and select your desired snippet from the list.

Starting 0.2.10, you can inject a dynamic snippet based on your Nuxtr Vue files configuration with `vueBase` or `vueBaseLayout`.
Starting 0.2.10, you can inject a dynamic snippet based on your Nuxtr Vue files configuration with `vueBase` or `nuxtBaseLayout`.

Nuxt Snippets are enabled by default. You can toggle them on or off using this setting:

Expand Down
40 changes: 32 additions & 8 deletions src/snippets/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CompletionItem, CompletionItemKind, MarkdownString, extensions, languages } from 'vscode';
import { resolve } from 'pathe';
import { readPackageJSON, writePackageJSON } from 'pkg-types'
import { homedir } from 'node:os';
import { generateVueFileBasicTemplate } from '../utils';
import { resolve } from 'pathe';
import { readPackageJSON, writePackageJSON } from 'pkg-types';
import { CompletionItem, CompletionItemKind, MarkdownString, extensions, languages } from 'vscode';
import { generateVueFileTemplate } from '../utils';

interface Snippet {
language: string;
Expand All @@ -17,7 +17,9 @@ export async function toggleSnippets(source: 'Nuxt' | 'Nitro', moveToDisabled: b

const extensionDir = resolve(homeDir, '.vscode', 'extensions', `${extensionName}-${nuxtrVersion}`);
const pkgJsonPath = resolve(extensionDir, 'package.json');

const pkgJSON = await readPackageJSON(extensionDir);

let snippets: Snippet[] = pkgJSON?.contributes?.snippets || [];
let disabledSnippets: Snippet[] = pkgJSON?.contributes?.disabled_snippets || [];

Expand Down Expand Up @@ -48,15 +50,37 @@ languages.registerCompletionItemProvider(
{ language: 'vue' },
{
provideCompletionItems() {
const completionItem = new CompletionItem('vueBaseLayout', CompletionItemKind.Snippet);
const completionItem = new CompletionItem('nuxtBaseLayout', CompletionItemKind.Snippet);
completionItem.detail = 'Generate a Nuxt Layout template';

const template = generateVueFileTemplate('layout');

const documentation = new MarkdownString();
documentation.appendMarkdown(`Generate a Nuxt layout template according to your Nuxtr configuration.\n\n`);
documentation.appendCodeblock(template, 'vue');

completionItem.documentation = documentation;
completionItem.kind = CompletionItemKind.Snippet;
completionItem.insertText = template;

return [completionItem];
}
}
);


languages.registerCompletionItemProvider(
{ language: 'vue' },
{
provideCompletionItems() {
const completionItem = new CompletionItem('vueBase', CompletionItemKind.Snippet);
completionItem.detail = 'Generate a Vue file template';

const template = generateVueFileBasicTemplate('layout');
const template = generateVueFileTemplate('page');

// Create a MarkdownString for documentation with code highlighting
const documentation = new MarkdownString();
documentation.appendMarkdown(`Generate a Vue file template according to your Nuxtr configuration.\n\n`);
documentation.appendCodeblock(template, 'vue'); // Specify 'vue' as the language for code block highlighting
documentation.appendCodeblock(template, 'vue');

completionItem.documentation = documentation;
completionItem.kind = CompletionItemKind.Snippet;
Expand Down

0 comments on commit 317a3c8

Please sign in to comment.