Skip to content

Commit

Permalink
Refactor: move function createDefinitionForElementInfo in function ge…
Browse files Browse the repository at this point in the history
…tDefinitionForDirectives as it is only referenced once
  • Loading branch information
WilsonZiweiWang committed Dec 4, 2023
1 parent 66ff8a9 commit 0b2a78b
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions server/src/connectionHandlers/onDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand All @@ -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
}

Expand Down

0 comments on commit 0b2a78b

Please sign in to comment.