Skip to content

Commit

Permalink
Feat: forward scan results from the process output to the server for …
Browse files Browse the repository at this point in the history
…further processing
  • Loading branch information
WilsonZiweiWang committed Jan 5, 2024
1 parent 427fd3d commit 6a1dbea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
4 changes: 3 additions & 1 deletion client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import { BitBakeProjectScanner } from './driver/BitBakeProjectScanner'
import { BitbakeDocumentLinkProvider } from './documentLinkProvider'
import { DevtoolWorkspacesView } from './ui/DevtoolWorkspacesView'
import { bitbakeESDKMode, setBitbakeESDKMode } from './driver/BitbakeESDK'
import { setLanguageClient } from './ui/BitbakeTerminal'

let client: LanguageClient
export let client: LanguageClient
const bitbakeDriver: BitbakeDriver = new BitbakeDriver()
let bitbakeTaskProvider: BitbakeTaskProvider
let taskProvider: vscode.Disposable
Expand Down Expand Up @@ -73,6 +74,7 @@ export async function activate (context: vscode.ExtensionContext): Promise<void>
bitbakeTaskProvider = new BitbakeTaskProvider(bitbakeDriver)
client = await activateLanguageServer(context)
bitBakeProjectScanner.setClient(client)
setLanguageClient(client)

taskProvider = vscode.tasks.registerTaskProvider('bitbake', bitbakeTaskProvider)

Expand Down
20 changes: 19 additions & 1 deletion client/src/ui/BitbakeTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ import { logger } from '../lib/src/utils/OutputLogger'
import path from 'path'
import { type BitbakeDriver } from '../driver/BitbakeDriver'
import { type BitbakeTaskDefinition } from './BitbakeTaskProvider'

import { RequestMethod } from '../lib/src/types/requests'
import { type LanguageClient } from 'vscode-languageclient/node'
const endOfLine: string = '\r\n'
const emphasisedAsterisk: string = '\x1b[7m * \x1b[0m'

let _languageClient: LanguageClient

export function setLanguageClient (client: LanguageClient): void {
_languageClient = client
}

/// Spawn a bitbake process in a dedicated terminal and wait for it to finish
export async function runBitbakeTerminal (bitbakeDriver: BitbakeDriver, bitbakeTaskDefinition: BitbakeTaskDefinition, terminalName: string, isBackground: boolean = false): Promise<child_process.ChildProcess> {
const command = bitbakeDriver.composeBitbakeCommand(bitbakeTaskDefinition)
Expand Down Expand Up @@ -58,6 +65,8 @@ export class BitbakePseudoTerminal implements vscode.Pseudoterminal {
onDidClose = this.closeEmitter.event
onDidChangeName = this.changeNameEmitter.event
lastExitCode: number = 0
outputDataString: string = ''
terminalName: string = ''

readonly parentTerminal: BitbakeTerminal | undefined
bitbakeDriver: BitbakeDriver
Expand Down Expand Up @@ -116,9 +125,14 @@ export class BitbakePseudoTerminal implements vscode.Pseudoterminal {
this.process = process
const processResolved = await this.process

this.outputDataString = ''
this.terminalName = terminalName ?? ''
processResolved.stdout?.on('data', (data) => {
this.output(data.toString())
logger.debug(data.toString())
if (terminalName !== undefined && terminalName.includes('Bitbake: Scan recipe env')) {
this.outputDataString += data.toString()
}
})
processResolved.stdout?.once('data', () => {
// I wanted to use appropriate events like process.on('spawn') or terminal.open() but they are not triggered at the right time for
Expand All @@ -139,6 +153,10 @@ export class BitbakePseudoTerminal implements vscode.Pseudoterminal {
processResolved.on('exit', (code) => {
this.lastExitCode = code ?? -1
this.process = undefined
if (this.terminalName.includes('Bitbake: Scan recipe env')) {
_languageClient === undefined && logger.error('Language client not set, unable to send request to the server to process scan results')
void _languageClient?.sendRequest(RequestMethod.ProcessRecipeScanResults, { scanResults: this.outputDataString })
}
if (code !== 0) {
this.output(emphasisedAsterisk + ' Bitbake process failed with code ' + code + '\n')
if (!this.isTaskTerminal()) {
Expand Down
4 changes: 4 additions & 0 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ connection.onRequest(RequestMethod.getLinksInDocument, (params: RequestParams['g
return analyzer.getLinksInStringContent(params.documentUri)
})

connection.onRequest(RequestMethod.ProcessRecipeScanResults, (param: RequestParams['ProcessRecipeScanResults']) => {
logger.debug(`[OnRequest] <ProcessRecipeScanResults> ${param.scanResults.length}`)
})

connection.onNotification(
NotificationMethod.FilenameChanged,
({ oldUriString, newUriString }: NotificationParams['FilenameChanged']): void => {
Expand Down

0 comments on commit 6a1dbea

Please sign in to comment.