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 1, 2023
1 parent 25235b9 commit 05ed54e
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 @@ -61,23 +61,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 @@ -86,25 +82,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 05ed54e

Please sign in to comment.