Skip to content

Commit

Permalink
feat(language-server): extract find-fn-line from go-to-action
Browse files Browse the repository at this point in the history
  • Loading branch information
DominusKelvin committed Sep 13, 2024
1 parent c3d2348 commit 418efd4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/language-server/helpers/find-fn-line.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const fs = require('fs').promises
const url = require('url')

module.exports = async function findFnLine(filePath) {
try {
const resolvedPath = filePath.startsWith('file:')
? url.fileURLToPath(filePath)
: filePath

const content = await fs.readFile(resolvedPath, 'utf8')
const lines = content.split('\n')
for (let i = 0; i < lines.length; i++) {
if (lines[i].includes('fn:')) {
return i // Return the line number (0-based index)
}
}
return 0 // If 'fn:' is not found, return the first line
} catch (error) {
return 0 // Return the first line if there's an error
}
}

0 comments on commit 418efd4

Please sign in to comment.