Skip to content

Commit

Permalink
Feat: Handle Bash tools
Browse files Browse the repository at this point in the history
  • Loading branch information
idillon-sfl committed Feb 6, 2024
1 parent a0c2434 commit 1c67851
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion client/src/lib/src/BitbakeSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function loadBitbakeSettings (settings: any, workspaceFolder: string): Bi
return resolvedSettings
}

function resolveSettingPath (configurationPath: string | undefined, variables: NodeJS.Dict<string>): string | undefined {
export function resolveSettingPath (configurationPath: string | undefined, variables: NodeJS.Dict<string>): string | undefined {
if (configurationPath === '' || configurationPath === undefined) {
return undefined
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ python do_build() {
}

do_build() {
bbwarn
oe_runmake
}
12 changes: 12 additions & 0 deletions integration-tests/src/tests/hover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,16 @@ suite('Bitbake Hover Test Suite', () => {
const expected = 'The default task for all recipes. This task depends on all other normal'
await testHover(position, expected)
}).timeout(BITBAKE_TIMEOUT)

test('Hover shows description for function defined into meta/classes-global/logging.bbclass', async () => {
const position = new vscode.Position(14, 6)
const expected = 'Function: **bbwarn** - *defined in'
await testHover(position, expected)
}).timeout(BITBAKE_TIMEOUT)

test('Hover shows description for function defined into meta/classes-global/base.bbclass', async () => {
const position = new vscode.Position(15, 6)
const expected = 'Function: **oe_runmake** - *defined in'
await testHover(position, expected)
}).timeout(BITBAKE_TIMEOUT)
})
14 changes: 13 additions & 1 deletion server/src/embedded-languages/bash-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const bashHeader = [
''
].join('\n')

export const generateBashEmbeddedLanguageDoc = (analyzedDocument: AnalyzedDocument): EmbeddedLanguageDoc => {
export const generateBashEmbeddedLanguageDoc = (analyzedDocument: AnalyzedDocument, pokyFolder?: string): EmbeddedLanguageDoc => {
const embeddedLanguageDoc = initEmbeddedLanguageDoc(analyzedDocument.document, 'bash')
TreeSitterUtils.forEach(analyzedDocument.tree.rootNode, (node) => {
switch (node.type) {
Expand All @@ -39,13 +39,25 @@ export const generateBashEmbeddedLanguageDoc = (analyzedDocument: AnalyzedDocume
}
})
insertBashHeader(embeddedLanguageDoc)
if (pokyFolder !== undefined) {
insertBashTools(embeddedLanguageDoc, pokyFolder)
}
return embeddedLanguageDoc
}

const insertBashHeader = (embeddedLanguageDoc: EmbeddedLanguageDoc): void => {
insertTextIntoEmbeddedLanguageDoc(embeddedLanguageDoc, 0, 0, bashHeader)
}

const insertBashTools = (embeddedLanguageDoc: EmbeddedLanguageDoc, pokyFolder: string): void => {
const bashTools = [
`. ${pokyFolder}/meta/classes-global/logging.bbclass`,
`. ${pokyFolder}/meta/classes-global/base.bbclass`,
''
].join('\n')
insertTextIntoEmbeddedLanguageDoc(embeddedLanguageDoc, 0, 0, bashTools)
}

const handleFunctionDefinitionNode = (node: SyntaxNode, embeddedLanguageDoc: EmbeddedLanguageDoc): void => {
insertTextIntoEmbeddedLanguageDoc(embeddedLanguageDoc, node.startIndex, node.endIndex, node.text)
node.children.forEach((child) => {
Expand Down
4 changes: 2 additions & 2 deletions server/src/embedded-languages/general-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import { generatePythonEmbeddedLanguageDoc } from './python-support'
import { type EmbeddedLanguageDoc, type EmbeddedLanguageType } from '../lib/src/types/embedded-languages'
import { analyzer } from '../tree-sitter/analyzer'

export const generateEmbeddedLanguageDocs = (textDocument: TextDocument): EmbeddedLanguageDoc[] | undefined => {
export const generateEmbeddedLanguageDocs = (textDocument: TextDocument, pokyFolder?: string): EmbeddedLanguageDoc[] | undefined => {
const analyzedDocument = analyzer.getAnalyzedDocument(textDocument.uri)
if (analyzedDocument === undefined) {
return
}
return [
generateBashEmbeddedLanguageDoc(analyzedDocument),
generateBashEmbeddedLanguageDoc(analyzedDocument, pokyFolder),
generatePythonEmbeddedLanguageDoc(analyzedDocument)
]
}
Expand Down
15 changes: 12 additions & 3 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import path from 'path'
import {
type Connection,
type InitializeResult,
Expand All @@ -28,12 +29,15 @@ import { getSemanticTokens, legend } from './semanticTokens'
import { bitBakeProjectScannerClient } from './BitbakeProjectScannerClient'
import { RequestMethod, type RequestParams, type RequestResult } from './lib/src/types/requests'
import { NotificationMethod, type NotificationParams } from './lib/src/types/notifications'
import { resolveSettingPath } from './lib/src/BitbakeSettings'

// Create a connection for the server. The connection uses Node's IPC as a transport
const connection: Connection = createConnection(ProposedFeatures.all)
const documents = new TextDocuments<TextDocument>(TextDocument)
let parseOnSave = true
let eSDKMode = false
let workspaceFolder: string | undefined
let pokyFolder: string | undefined

const disposables: Disposable[] = []

Expand All @@ -50,6 +54,8 @@ connection.onInitialize(async (params: InitializeParams): Promise<InitializeResu
bitBakeProjectScannerClient.setConnection(connection)
disposables.push(...bitBakeProjectScannerClient.buildHandlers())

workspaceFolder = params.workspaceFolders?.[0].uri.replace('file://', '')

const extensionPath = params.initializationOptions.extensionPath as string

logger.info('[onInitialize] Setting yocto doc path and parsing doc files')
Expand Down Expand Up @@ -85,11 +91,14 @@ connection.onShutdown(() => {
disposables.forEach((disposable) => { disposable.dispose() })
})

// eslint-disable-next-line @typescript-eslint/no-misused-promises
connection.onDidChangeConfiguration(async (change) => {
connection.onDidChangeConfiguration((change) => {
logger.level = change.settings.bitbake.loggingLevel
parseOnSave = change.settings.bitbake.parseOnSave
eSDKMode = change.settings.bitbake.eSDKMode
const bitbakeFolder = resolveSettingPath(change.settings.bitbake.pathToBitbakeFolder, { workspaceFolder })
if (bitbakeFolder !== undefined) {
pokyFolder = path.join(bitbakeFolder, '..') // We assume BitBake is into Poky
}
})

connection.onCompletion(onCompletionHandler)
Expand Down Expand Up @@ -134,7 +143,7 @@ const analyzeDocument = async (event: TextDocumentChangeEvent<TextDocument>): Pr
const previousVersion = analyzer.getAnalyzedDocument(textDocument.uri)?.version ?? -1
if (textDocument.getText().length > 0 && previousVersion < textDocument.version) {
const diagnostics = analyzer.analyze({ document: textDocument, uri: textDocument.uri })
const embeddedLanguageDocs: NotificationParams['EmbeddedLanguageDocs'] | undefined = generateEmbeddedLanguageDocs(event.document)
const embeddedLanguageDocs: NotificationParams['EmbeddedLanguageDocs'] | undefined = generateEmbeddedLanguageDocs(event.document, pokyFolder)
if (embeddedLanguageDocs !== undefined) {
void connection.sendNotification(NotificationMethod.EmbeddedLanguageDocs, embeddedLanguageDocs)
}
Expand Down

0 comments on commit 1c67851

Please sign in to comment.