From 0b2a78b2c0e08b8d5a18c7cfca5ba2c46ffaf70e Mon Sep 17 00:00:00 2001 From: Ziwei Wang Date: Thu, 30 Nov 2023 16:56:50 -0500 Subject: [PATCH] Refactor: move function createDefinitionForElementInfo in function getDefinitionForDirectives as it is only referenced once --- server/src/connectionHandlers/onDefinition.ts | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/server/src/connectionHandlers/onDefinition.ts b/server/src/connectionHandlers/onDefinition.ts index c19d8ed3..ac95cc08 100644 --- a/server/src/connectionHandlers/onDefinition.ts +++ b/server/src/connectionHandlers/onDefinition.ts @@ -75,23 +75,19 @@ export function onDefinitionHandler (textDocumentPositionParams: TextDocumentPos } function getDefinitionForDirectives (directiveStatementKeyword: DirectiveStatementKeyword, symbol: string): Definition { - let definition: Definition = [] - + let elementInfos: ElementInfo[] = [] switch (directiveStatementKeyword) { case 'inherit': - { - const elementInfos = bitBakeProjectScannerClient.bitbakeScanResult._classes.filter((bbclass): boolean => { - return bbclass.name === symbol - }) - definition = createDefinitionForElementInfo(elementInfos) - } + elementInfos = bitBakeProjectScannerClient.bitbakeScanResult._classes.filter((bbclass): boolean => { + return bbclass.name === symbol + }) break case 'require': case 'include': { const includeFile = path.parse(symbol) - let elementInfos = bitBakeProjectScannerClient.bitbakeScanResult._includes.filter((incFile): boolean => { + elementInfos = bitBakeProjectScannerClient.bitbakeScanResult._includes.filter((incFile): boolean => { return incFile.name === includeFile.name }) @@ -100,25 +96,20 @@ function getDefinitionForDirectives (directiveStatementKeyword: DirectiveStateme return recipe.name === includeFile.name }) } - definition = createDefinitionForElementInfo(elementInfos) } break default: + return [] } - return definition -} -function createDefinitionForElementInfo (elementInfos: ElementInfo[]): Definition { const definition: Definition = [] - for (const elementInfo of elementInfos) { if (elementInfo.path !== undefined) { const location: Location = createDefinitionLocationForPathInfo(elementInfo.path) definition.push(location) } } - return definition }