Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go to definition for symbols in declaration and variable expansion syntax in the current file and included files #9

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 114 additions & 42 deletions server/src/__tests__/analyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,44 @@ describe('analyze', () => {

const globalDeclarations = analyzer.getGlobalDeclarationSymbols(DUMMY_URI)

expect(globalDeclarations).toEqual(
expect.arrayContaining([
{
kind: 13,
location: {
range: {
end: {
character: 11,
line: 1
},
start: {
character: 0,
line: 1
}
},
uri: DUMMY_URI
},
name: 'BAR'
},
{
kind: 13,
location: {
range: {
end: {
character: 11,
line: 0
},
start: {
character: 0,
line: 0
}
},
uri: DUMMY_URI
},
name: 'FOO'
}
])
)
expect(globalDeclarations).toMatchInlineSnapshot(`
[
{
Expand Down Expand Up @@ -241,70 +279,104 @@ describe('sourceIncludeFiles', () => {
expect(symbols).toEqual(
expect.arrayContaining([
expect.objectContaining({
DESCRIPTION: expect.objectContaining({
name: 'DESCRIPTION',
location: {
uri: FIXTURE_URI.BAR_INC,
range: {
start: {
line: 0,
character: 0
},
end: {
line: 0,
character: 23
DESCRIPTION: expect.arrayContaining([
expect.objectContaining({
name: 'DESCRIPTION',
location: {
uri: FIXTURE_URI.BAR_INC,
range: {
start: {
line: 0,
character: 0
},
end: {
line: 0,
character: 23
}
}
}
}
})
})
])
})
])
)

expect(symbols).toEqual(
expect.arrayContaining([
expect.objectContaining({
DESCRIPTION: expect.objectContaining({
name: 'DESCRIPTION',
location: {
uri: FIXTURE_URI.FOO_INC,
range: {
start: {
line: 0,
character: 0
},
end: {
line: 0,
character: 23
DESCRIPTION: expect.arrayContaining([
expect.objectContaining({
name: 'DESCRIPTION',
location: {
uri: FIXTURE_URI.FOO_INC,
range: {
start: {
line: 0,
character: 0
},
end: {
line: 0,
character: 23
}
}
}
}
})
})
])
})
])
)

expect(symbols).toEqual(
expect.arrayContaining([
expect.objectContaining({
DESCRIPTION: expect.objectContaining({
name: 'DESCRIPTION',
location: {
uri: FIXTURE_URI.BAZ_BBCLASS,
range: {
start: {
line: 0,
character: 0
},
end: {
line: 0,
character: 27
DESCRIPTION: expect.arrayContaining([
expect.objectContaining({
name: 'DESCRIPTION',
location: {
uri: FIXTURE_URI.BAZ_BBCLASS,
range: {
start: {
line: 0,
character: 0
},
end: {
line: 0,
character: 27
}
}
}
}
})
})
])
})
])
)
})
})

describe('declarations', () => {
beforeEach(() => {
jest.clearAllMocks()
})

it('gets all symbols in the declaration statements with duplicates', async () => {
const analyzer = await getAnalyzer()
const document = FIXTURE_DOCUMENT.COMPLETION
const uri = FIXTURE_URI.COMPLETION

await analyzer.analyze({
document,
uri
})

const symbols = analyzer.getGlobalDeclarationSymbols(uri)

let occurances = 0
symbols.forEach((symbol) => {
if (symbol.name === 'MYVAR') {
occurances++
}
})

expect(occurances).toEqual(5)
})
})
57 changes: 34 additions & 23 deletions server/src/__tests__/completions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,32 @@ describe('On Completion', () => {
expect(result).toEqual([])
})

it("doesn't provide duplicate completion items for local custom variables", async () => {
await analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.COMPLETION
})

const result = onCompletionHandler({
textDocument: {
uri: DUMMY_URI
},
position: {
line: 0,
character: 0
}
})

let occurances = 0
result.forEach((item) => {
if (item.label === 'MYVAR') {
occurances++
}
})

expect(occurances).toBe(1)
})

it('provides necessary suggestions when it is in variable expansion', async () => {
await analyzer.analyze({
uri: DUMMY_URI,
Expand Down Expand Up @@ -636,13 +662,19 @@ describe('On Completion', () => {
character: 0
}
})
// Show only one completion item for each symbol
let occurances = 0
result.forEach(item => {
item.label === 'DESCRIPTION' && occurances++
})

expect(occurances).toEqual(1)
expect(result).toEqual(
expect.arrayContaining([
expect.objectContaining({
label: 'DESCRIPTION',
labelDetails: {
description: path.relative(FIXTURE_URI.DIRECTIVE.replace('file://', ''), FIXTURE_URI.BAR_INC.replace('file://', ''))
description: path.relative(FIXTURE_URI.DIRECTIVE.replace('file://', ''), FIXTURE_URI.FOO_INC.replace('file://', '')) // In this test case, the one that remains after the filtering is the relative path from directive.bb to foo.inc
}
})
])
Expand All @@ -659,27 +691,6 @@ describe('On Completion', () => {
])
)

expect(result).toEqual(
expect.arrayContaining([
expect.objectContaining({
label: 'DESCRIPTION',
labelDetails: {
description: path.relative(FIXTURE_URI.DIRECTIVE.replace('file://', ''), FIXTURE_URI.FOO_INC.replace('file://', ''))
}
})
])
)

expect(result).toEqual(
expect.arrayContaining([
expect.objectContaining({
label: 'DESCRIPTION',
labelDetails: {
description: path.relative(FIXTURE_URI.DIRECTIVE.replace('file://', ''), FIXTURE_URI.BAZ_BBCLASS.replace('file://', ''))
}
})
])
)
bitBakeDocScanner.parseBitbakeVariablesFile()
bitBakeDocScanner.parseYoctoVariablesFile()

Expand All @@ -698,7 +709,7 @@ describe('On Completion', () => {
expect.objectContaining({
label: 'DESCRIPTION',
labelDetails: {
description: path.relative(FIXTURE_URI.DIRECTIVE.replace('file://', ''), FIXTURE_URI.BAZ_BBCLASS.replace('file://', ''))
description: path.relative(FIXTURE_URI.DIRECTIVE.replace('file://', ''), FIXTURE_URI.FOO_INC.replace('file://', ''))
},
documentation: {
value: '```man\nDESCRIPTION (bitbake-language-server)\n\n\n```\n```bitbake\n\n```\n---\n The package description used by package managers. If not set,\n `DESCRIPTION` takes the value of the `SUMMARY`\n variable.\n\n\n[Reference](https://docs.yoctoproject.org/ref-manual/variables.html#term-DESCRIPTION)',
Expand Down
Loading
Loading