Skip to content

Commit

Permalink
Feature: Add completion items for overrides
Browse files Browse the repository at this point in the history
The bitbake scanner provides the list of active overrides. It is not
recipe specific to be faster.
  • Loading branch information
deribaucourt committed Nov 2, 2023
1 parent 92ddf45 commit 102c252
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
14 changes: 14 additions & 0 deletions server/src/BitBakeProjectScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class BitBakeProjectScanner {
private _classes: ElementInfo[] = new Array < ElementInfo >()
private _includes: ElementInfo[] = new Array < ElementInfo >()
private _recipes: ElementInfo[] = new Array < ElementInfo >()
private _overrides: string[] = []
private _shouldDeepExamine: boolean = false
private readonly _bitbakeDriver: BitbakeDriver = new BitbakeDriver()

Expand All @@ -48,6 +49,10 @@ export class BitBakeProjectScanner {
scanIsPending: false
}

get overrides (): string[] {
return this._overrides
}

get bitbakeDriver (): BitbakeDriver {
return this._bitbakeDriver
}
Expand Down Expand Up @@ -90,6 +95,7 @@ export class BitBakeProjectScanner {
this.scanForIncludeFiles()
this.scanForRecipes()
this.scanRecipesAppends()
this.scanOverrides()

logger.info('scan ready')
this.printScanStatistic()
Expand Down Expand Up @@ -117,6 +123,7 @@ export class BitBakeProjectScanner {
logger.info(`Recipes: ${this._recipes.length}`)
logger.info(`Inc-Files: ${this._includes.length}`)
logger.info(`bbclass: ${this._classes.length}`)
logger.info(`overrides: ${this._overrides.length}`)
}

private scanForClasses (): void {
Expand Down Expand Up @@ -231,6 +238,13 @@ export class BitBakeProjectScanner {
this.scanForRecipesPath()
}

scanOverrides (): void {
const commandResult = this.executeBitBakeCommand('bitbake-getvar OVERRIDES')
const output = commandResult.output.toString()
const outerReg = /\nOVERRIDES="(.*)"\n/
this._overrides = output.match(outerReg)?.[1].split(':') ?? []
}

parseAllRecipes (): boolean {
logger.debug('parseAllRecipes')
let parsingSuccess: boolean = true
Expand Down
12 changes: 11 additions & 1 deletion server/src/connectionHandlers/onCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { formatCompletionItems } from '../completions/snippet-utils'
import { bitBakeDocScanner } from '../BitBakeDocScanner'
import { BITBAKE_OPERATOR } from '../completions/bitbake-operator'
import { VARIABLE_FLAGS } from '../completions/variable-flags'
import bitBakeProjectScanner from '../BitBakeProjectScanner'

export function onCompletionHandler (textDocumentPositionParams: TextDocumentPositionParams): CompletionItem[] {
logger.debug('onCompletion')
Expand Down Expand Up @@ -59,7 +60,16 @@ export function onCompletionHandler (textDocumentPositionParams: TextDocumentPos
}
})

return bitBakeOperatorCompletionItems
const bitbakeOverridesCompletionItems: CompletionItem[] = bitBakeProjectScanner.overrides.map((override, index) => {
return {
label: override,
kind: CompletionItemKind.Property,
// Present overrides after operators, in order of priority
sortText: '~' + String.fromCharCode(21 + index) + override
}
})

return [...bitBakeOperatorCompletionItems, ...bitbakeOverridesCompletionItems]
} else {
return []
}
Expand Down

0 comments on commit 102c252

Please sign in to comment.