-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(language-server): extract find-fn-line from go-to-action
- Loading branch information
1 parent
c3d2348
commit 418efd4
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |