Skip to content

Commit

Permalink
Refactor: Rename getGlobalDeclarationSymbols to getGlobalDeclarationS…
Browse files Browse the repository at this point in the history
…ymbolsForUri
  • Loading branch information
WilsonZiweiWang authored and idillon-sfl committed May 22, 2024
1 parent 10734be commit 2d50f37
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions server/src/__tests__/analyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('analyze', () => {
document: FIXTURE_DOCUMENT.DECLARATION
})

const globalDeclarations = analyzer.getGlobalDeclarationSymbols(DUMMY_URI)
const globalDeclarations = analyzer.getGlobalDeclarationSymbolsForUri(DUMMY_URI)

expect(globalDeclarations).toEqual(
expect.arrayContaining([
Expand Down Expand Up @@ -261,7 +261,7 @@ describe('sourceIncludeFiles', () => {
analyzer.extractIncludeFileUris(uri)

const symbols = analyzer.getIncludeUrisForUri(uri).map((includeUri) => {
return analyzer.getGlobalDeclarationSymbols(includeUri)
return analyzer.getGlobalDeclarationSymbolsForUri(includeUri)
}).flat()

expect(symbols).toEqual(
Expand Down Expand Up @@ -334,7 +334,7 @@ describe('declarations', () => {
uri
})

const symbols = analyzer.getGlobalDeclarationSymbols(uri)
const symbols = analyzer.getGlobalDeclarationSymbolsForUri(uri)

let occurances = 0
symbols.forEach((symbol) => {
Expand Down
4 changes: 2 additions & 2 deletions server/src/connectionHandlers/onCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ const allCommonDirectoriesCompletionItems: CompletionItem[] = Array.from(commonD
function getSymbolCompletionItems (word: string | null): CompletionItem[] {
if (word !== null) {
const uniqueSymbolSet = new Set()
const globalDeclarationSymbols = analyzer.getGlobalDeclarationSymbols(documentUri).filter(symbol => {
const globalDeclarationSymbols = analyzer.getGlobalDeclarationSymbolsForUri(documentUri).filter(symbol => {
if (!uniqueSymbolSet.has(symbol.name)) {
uniqueSymbolSet.add(symbol.name)
return true
Expand Down Expand Up @@ -397,7 +397,7 @@ function convertExtraSymbolsToCompletionItems (uri: string): CompletionItem[] {
logger.debug(`[onCompletion] convertSymbolsToCompletionItems: ${uri}`)
let completionItems: CompletionItem[] = []
analyzer.getIncludeUrisForUri(uri).map((includeUri) => {
return analyzer.getGlobalDeclarationSymbols(includeUri)
return analyzer.getGlobalDeclarationSymbolsForUri(includeUri)
})
.flat()
.reduce<BitbakeSymbolInformation[]>((acc, symbol) => {
Expand Down
4 changes: 2 additions & 2 deletions server/src/connectionHandlers/onDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ export function getAllDefinitionSymbolsForSymbolAtPoint (uri: string, word: stri
return []
}
const allDeclarationSymbols = [
...analyzer.getGlobalDeclarationSymbols(uri)
...analyzer.getGlobalDeclarationSymbolsForUri(uri)
]
analyzer.getIncludeUrisForUri(uri)?.forEach((includeFileUri) => {
allDeclarationSymbols.push(...analyzer.getGlobalDeclarationSymbols(includeFileUri))
allDeclarationSymbols.push(...analyzer.getGlobalDeclarationSymbolsForUri(includeFileUri))
})

return allDeclarationSymbols.filter(symbol => symbol.name === word && symbol.kind === symbolAtPoint?.kind)
Expand Down
6 changes: 3 additions & 3 deletions server/src/connectionHandlers/onHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function onHoverHandler (params: HoverParams): Promise<Hover | null

// Show documentation of a bitbake variable
// Triggers on global declaration expressions like "VAR = 'foo'" and inside variable expansion like "FOO = ${VAR}" but skip the ones like "python VAR(){}"
const canShowHoverDefinitionForVariableName: boolean = (analyzer.getGlobalDeclarationSymbols(textDocument.uri).some((symbol) => symbol.name === word) && analyzer.isIdentifierOfVariableAssignment(params)) || analyzer.isVariableExpansion(textDocument.uri, position.line, position.character) || analyzer.isPythonDatastoreVariable(textDocument.uri, position.line, position.character) || analyzer.isBashVariableExpansion(textDocument.uri, position.line, position.character)
const canShowHoverDefinitionForVariableName: boolean = (analyzer.getGlobalDeclarationSymbolsForUri(textDocument.uri).some((symbol) => symbol.name === word) && analyzer.isIdentifierOfVariableAssignment(params)) || analyzer.isVariableExpansion(textDocument.uri, position.line, position.character) || analyzer.isPythonDatastoreVariable(textDocument.uri, position.line, position.character) || analyzer.isBashVariableExpansion(textDocument.uri, position.line, position.character)
if (canShowHoverDefinitionForVariableName) {
const found = [
...bitBakeDocScanner.bitbakeVariableInfo.filter((bitbakeVariable) => !bitBakeDocScanner.yoctoVariableInfo.some(yoctoVariable => yoctoVariable.name === bitbakeVariable.name)),
Expand Down Expand Up @@ -121,11 +121,11 @@ export async function onHoverHandler (params: HoverParams): Promise<Hover | null
}

function getGlobalSymbolComments (uri: string, word: string, currentSymbolAtPoint: BitbakeSymbolInformation): string | null {
const localSymbolsWithComments = analyzer.getGlobalDeclarationSymbols(uri).filter((symbol) => symbol.name === word).filter((symbol) => symbol.commentsAbove.length > 0)
const localSymbolsWithComments = analyzer.getGlobalDeclarationSymbolsForUri(uri).filter((symbol) => symbol.name === word).filter((symbol) => symbol.commentsAbove.length > 0)
const externalSymbolsWithComments: BitbakeSymbolInformation[] = []

analyzer.getIncludeUrisForUri(uri).forEach((includeFileUri) => {
externalSymbolsWithComments.push(...analyzer.getGlobalDeclarationSymbols(includeFileUri).filter((symbol) => symbol.name === word).filter((symbol) => symbol.commentsAbove.length > 0))
externalSymbolsWithComments.push(...analyzer.getGlobalDeclarationSymbolsForUri(includeFileUri).filter((symbol) => symbol.name === word).filter((symbol) => symbol.commentsAbove.length > 0))
})
const priority = ['.bbclass', '.conf', '.inc', '.bb', '.bbappend']

Expand Down
4 changes: 2 additions & 2 deletions server/src/tree-sitter/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default class Analyzer {

public getAllSymbols (uri: string): BitbakeSymbolInformation[] {
return [
...this.getGlobalDeclarationSymbols(uri),
...this.getGlobalDeclarationSymbolsForUri(uri),
...this.getVariableExpansionSymbols(uri),
...this.getPythonDatastoreVariableSymbols(uri)
]
Expand Down Expand Up @@ -185,7 +185,7 @@ export default class Analyzer {
return { variableExpansionSymbols, pythonDatastoreVariableSymbols }
}

public getGlobalDeclarationSymbols (uri: string): BitbakeSymbolInformation[] {
public getGlobalDeclarationSymbolsForUri (uri: string): BitbakeSymbolInformation[] {
const analyzedDocument = this.uriToAnalyzedDocument[uri]
if (analyzedDocument !== undefined) {
const { globalDeclarations } = analyzedDocument
Expand Down

0 comments on commit 2d50f37

Please sign in to comment.