Skip to content

Commit

Permalink
feat(goToDefinitions): add settings to configure template definitions (
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilanaya authored Jan 31, 2024
1 parent ceb2a49 commit e2abdcb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/configurationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export type Configuration = {
* @default true
* */
enableLinks: boolean
/**
* Whether to enable definitions for template attributes
* May lead to definition duplicates with Volar configured
* @default true,
* */
enableTemplateAttributeDefinitions: boolean
/**
* (component definitions) Try to resolve imports using aliases from root webpack config
* @default true
Expand Down
6 changes: 4 additions & 2 deletions src/gotoDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import * as vscode from 'vscode'
import { pascalCase, camelCase } from 'change-case'
import { documentsImportsCache } from './componentsLinks'
import { getDefaultExportOutline, interpolationPropRegex, isScriptSetup } from './util'
import { getExtensionSetting } from 'vscode-framework'

export const registerGotoDefinition = () => {
// attribute definition
vscode.languages.registerDefinitionProvider('vue', {
async provideDefinition(document, position, token) {
async provideDefinition(document, position) {
if (!getExtensionSetting('enableTemplateAttributeDefinitions')) return

const lineText = document.lineAt(position).text
const match = interpolationPropRegex.exec(lineText.slice(0, position.character))
if (!match) return
Expand Down Expand Up @@ -38,7 +41,6 @@ export const registerGotoDefinition = () => {
console.warn('no importsCache!')
return
}

// Volar with configured aliases in tsconfig already provides correct definition
if (await isScriptSetup(document.uri)) return

Expand Down

0 comments on commit e2abdcb

Please sign in to comment.