|
| 1 | +import * as vscode from 'vscode' |
1 | 2 | import { parseTree, findNodeAtLocation, getNodeValue, Node } from 'jsonc-parser' |
2 | 3 | import { compact } from 'lodash' |
3 | | -import * as vscode from 'vscode' |
4 | 4 | import { getExtensionSetting, getExtensionCommandId } from 'vscode-framework' |
5 | 5 | import { packageJsonSelector } from './packageJsonComplete' |
6 | 6 |
|
@@ -29,15 +29,16 @@ export const registerPackageJsonLinks = () => { |
29 | 29 | const targetScriptNode = scriptsNodes.find(node => node.children![0]!.value === scriptRefName)?.children?.[1] |
30 | 30 | if (!targetScriptNode) continue |
31 | 31 | const getNodeStringStart = (node: Node) => node.offset + 1 |
32 | | - const startOffset = getNodeStringStart(scriptNode) + match.index + match[1]!.length |
33 | | - const positions = [startOffset, startOffset + scriptRefName.length].map(offset => document.positionAt(offset)) as [ |
| 32 | + let startOffset = getNodeStringStart(scriptNode) + match.index + match[1]!.length |
| 33 | + if (match[0]!.startsWith('"')) startOffset += 1 |
| 34 | + const { line: targetScriptLine, character: targetScriptCharacter } = document.positionAt(getNodeStringStart(targetScriptNode)) |
| 35 | + const fragment = `L${targetScriptLine + 1},${targetScriptCharacter + 1}` |
| 36 | + const linkPositions = [startOffset, startOffset + scriptRefName.length].map(offset => document.positionAt(offset)) as [ |
34 | 37 | vscode.Position, |
35 | 38 | vscode.Position, |
36 | 39 | ] |
37 | | - const { line: targetScriptLine, character: targetScriptCharacter } = document.positionAt(getNodeStringStart(targetScriptNode)) |
38 | | - const fragment = `L${targetScriptLine + 1},${targetScriptCharacter + 1}` |
39 | 40 | links.push({ |
40 | | - range: new vscode.Range(...positions), |
| 41 | + range: new vscode.Range(...linkPositions), |
41 | 42 | tooltip: 'Reveal script', |
42 | 43 | target: document.uri.with({ fragment }), |
43 | 44 | }) |
|
0 commit comments