From d6856b05af9fb7962d0dc0ee1fcdbb938cdd9d66 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sun, 23 Jul 2023 21:00:35 +0200 Subject: [PATCH 1/4] Fix jumping to lambda parameters --- src/features/jump-to-definition.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/jump-to-definition.ts b/src/features/jump-to-definition.ts index bfb0d87..cf21ab8 100644 --- a/src/features/jump-to-definition.ts +++ b/src/features/jump-to-definition.ts @@ -566,7 +566,7 @@ 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': From 650c2e2d1badfe7deef25acf5f8bcc31073cdfb1 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sun, 23 Jul 2023 21:40:58 +0200 Subject: [PATCH 2/4] Fix jumping to let destructuring --- src/features/jump-to-definition.ts | 43 ++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/src/features/jump-to-definition.ts b/src/features/jump-to-definition.ts index cf21ab8..ae1f061 100644 --- a/src/features/jump-to-definition.ts +++ b/src/features/jump-to-definition.ts @@ -572,24 +572,51 @@ const provider = (globalState: GlobalState) => { 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': From 2fd4ae8a49b64eaee722900a8a6066b489fb003d Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sun, 23 Jul 2023 21:48:02 +0200 Subject: [PATCH 3/4] Fix jumping to as pattern in function argument --- src/features/jump-to-definition.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/features/jump-to-definition.ts b/src/features/jump-to-definition.ts index ae1f061..9f664fb 100644 --- a/src/features/jump-to-definition.ts +++ b/src/features/jump-to-definition.ts @@ -712,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': From 9ed858ee4bfdfc8510ddf59ad491cf995a378542 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sun, 23 Jul 2023 21:51:10 +0200 Subject: [PATCH 4/4] Fix jumping to record destructuring in function argument --- src/features/jump-to-definition.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/features/jump-to-definition.ts b/src/features/jump-to-definition.ts index 9f664fb..d76becf 100644 --- a/src/features/jump-to-definition.ts +++ b/src/features/jump-to-definition.ts @@ -747,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