Skip to content

Commit

Permalink
fix: handle hover in parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
x1unix committed Oct 6, 2024
1 parent ac9a420 commit 753d959
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ const getLineTokens = (str: string, lang: string): monaco.Token[] | null => {
}
}

const checkPackageNameToken = (tokens: monaco.Token[], tokenPos: number) => {
const isDerefOrPtrToken = (line: string, tokens: monaco.Token[], tokenPos: number) => {
const str = tokenToString(line, tokens, tokenPos)
switch (str) {
case '*':
case '&':
return true
default:
return false
}
}

const checkPackageNameToken = (line: string, tokens: monaco.Token[], tokenPos: number) => {
let identPos = -1
let foundIdent = false
let foundDot = false
Expand All @@ -28,7 +39,7 @@ const checkPackageNameToken = (tokens: monaco.Token[], tokenPos: number) => {
switch (tok.type) {
case GoToken.Dot:
if (foundDot || foundIdent) {
return -1
return isDerefOrPtrToken(line, tokens, i) && foundIdent ? identPos : -1
}

foundDot = true
Expand Down Expand Up @@ -82,7 +93,7 @@ const resolveHoverValue = (line: string, tokens: monaco.Token[], tokenPos: numbe
}

// check if there is a symbol behind to determine direction to move.
const pkgNamePos = checkPackageNameToken(tokens, tokenPos - 1)
const pkgNamePos = checkPackageNameToken(line, tokens, tokenPos - 1)
if (pkgNamePos === -1) {
return { value: hoverValue, range }
}
Expand Down

0 comments on commit 753d959

Please sign in to comment.