Skip to content

Commit

Permalink
Merge pull request #12 from lydell/fix-jump-to-definition
Browse files Browse the repository at this point in the history
Fix jumping to definitions
  • Loading branch information
ryan-haskell authored Jul 24, 2023
2 parents fa73f14 + 9ed858e commit c80b8ac
Showing 1 changed file with 44 additions and 11 deletions.
55 changes: 44 additions & 11 deletions src/features/jump-to-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,30 +566,57 @@ const provider = (globalState: GlobalState) => {
let item = expression.value.lambda.expression
let range = sharedLogic.fromElmRange(item.range)
if (range.contains(position)) {
return findLocationOfItemsForExpression(item, args, localDeclarations, localPatterns)
return findLocationOfItemsForExpression(item, args, localDeclarations, localPatterns.concat(patterns))
}
return null
case 'let':
let letDeclarations = expression.value.let.declarations
let newLocalDeclarations = localDeclarations.concat(letDeclarations)
let newLocalPatterns =
localPatterns.concat(
letDeclarations.flatMap(letDeclaration => {
switch (letDeclaration.value.type) {
case 'function':
return []
case 'destructuring':
return letDeclaration.value.destructuring.pattern
}
})
)

// Handle declarations between "let" and "in" keywords
for (let declaration of letDeclarations) {
let range = sharedLogic.fromElmRange(declaration.range)
if (range.contains(position) && ElmSyntax.isFunctionDeclaration(declaration)) {
return findLocationForFunctionDeclaration(
declaration.value.function,
args,
newLocalDeclarations,
localPatterns
)
if (range.contains(position)) {
switch (declaration.value.type) {
case 'function':
return findLocationForFunctionDeclaration(
declaration.value.function,
args,
newLocalDeclarations,
newLocalPatterns
)
case 'destructuring':
let pattern = declaration.value.destructuring.pattern

let patternRange = sharedLogic.fromElmRange(pattern.range)
if (patternRange.contains(position)) {
return findLocationOfCustomTypeForPattern(pattern.value, patternRange)
}

let item = declaration.value.destructuring.expression
let itemRange = sharedLogic.fromElmRange(item.range)
if (itemRange.contains(position)) {
return findLocationOfItemsForExpression(item, args, localDeclarations, newLocalPatterns.concat([pattern]))
}
}
}
}

// Handle expression after the "in" keyword
let range2 = sharedLogic.fromElmRange(expression.value.let.expression.range)
if (range2.contains(position)) {
return findLocationOfItemsForExpression(expression.value.let.expression, args, newLocalDeclarations, localPatterns)
return findLocationOfItemsForExpression(expression.value.let.expression, args, newLocalDeclarations, newLocalPatterns)
}
return null
case 'list':
Expand Down Expand Up @@ -685,7 +712,11 @@ const provider = (globalState: GlobalState) => {
case 'all':
return null
case 'as':
return null
if (argument.value.as.name.value === name) {
return argument.value.as.name.range
} else {
return null
}
case 'char':
return null
case 'float':
Expand Down Expand Up @@ -716,7 +747,9 @@ const provider = (globalState: GlobalState) => {
case 'record':
let matchingNode = argument.value.record.value.find(x => x.value === name)
if (matchingNode) {
matchingNode.range
return matchingNode.range
} else {
return null
}
case 'string':
return null
Expand Down

0 comments on commit c80b8ac

Please sign in to comment.