Skip to content

Commit

Permalink
fix(language-server): normalize helper path
Browse files Browse the repository at this point in the history
  • Loading branch information
DominusKelvin committed Sep 13, 2024
1 parent 4c46947 commit f1c8da6
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/language-server/go-to-definitions/go-to-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ const fs = require('fs').promises
const findProjectRoot = require('../helpers/find-project-root')
const findFnLine = require('../helpers/find-fn-line')

function camelToKebabCase(str) {
return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)
}

function normalizeHelperPath(helperPath) {
const parts = helperPath.split('/')
const fileName = parts.pop() // Get the last part (file name)
const normalizedFileName = camelToKebabCase(fileName)
return [...parts, normalizedFileName].join('/')
}

module.exports = async function goToHelper(document, position) {
const helperInfo = extractHelperInfo(document, position)

Expand All @@ -12,9 +23,11 @@ module.exports = async function goToHelper(document, position) {
}

const projectRoot = await findProjectRoot(document.uri)
const normalizedHelperPath = normalizeHelperPath(
helperInfo.helperPath.join('/')
)
const fullHelperPath =
path.join(projectRoot, 'api', 'helpers', ...helperInfo.helperPath) + '.js'

path.join(projectRoot, 'api', 'helpers', normalizedHelperPath) + '.js'
if (fullHelperPath) {
const fnLineNumber = await findFnLine(fullHelperPath)
return lsp.Location.create(
Expand Down

0 comments on commit f1c8da6

Please sign in to comment.