Skip to content

Commit

Permalink
Chore: Only show comments for symbols that don't have docs from yocto…
Browse files Browse the repository at this point in the history
…/bitbake
  • Loading branch information
WilsonZiweiWang committed Dec 21, 2023
1 parent e203a66 commit 3d76325
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
5 changes: 2 additions & 3 deletions server/src/__tests__/fixtures/directive.bb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ SYMBOL_IN_STRING = 'hover is a package ${FOO} \
this hover too, other words should not. \
'
# comment 1 for DESCRIPTION line 1
# comment 1 for DESCRIPTION line 2
DESCRIPTION = 'file://dummy.patch'
# comment 2 for DESCRIPTION
DESCRIPTION += 'file://dummy-2.patch'
# comment 1 for custom variable MYVAR
MYVAR = '123'
# comment 2 for custom variable MYVAR
MYVAR:append = '456'
# comment 1 for do_build
do_build(){

Expand Down
34 changes: 17 additions & 17 deletions server/src/__tests__/hover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ describe('on hover', () => {
uri: DUMMY_URI
},
position: {
line: 13,
line: 14,
character: 1
}
})
Expand All @@ -510,66 +510,66 @@ describe('on hover', () => {
uri: DUMMY_URI
},
position: {
line: 17,
line: 22,
character: 1
}
})

const shouldShow3 = await onHoverHandler({
const shouldNotShow1 = await onHoverHandler({
textDocument: {
uri: DUMMY_URI
},
position: {
line: 19,
line: 12,
character: 1
}
})

const shouldShow4 = await onHoverHandler({
const shouldNotShow2 = await onHoverHandler({
textDocument: {
uri: DUMMY_URI
},
position: {
line: 23,
line: 18,
character: 1
}
})

const DUMMY_URI_TRIMMED = DUMMY_URI.replace('file://', '')
// 1. should show all comments above

// 1. should show all comments above the symbols that don't have docs from yocto/bitbake
// 2. should show comments for all declarations for the same variable in the same file
// 3. TODO: should show comments for the same variable in the include files
// 3. should show comments for the same variable in the include files
expect(shouldShow1).toEqual(
expect.objectContaining({
contents: expect.objectContaining({
value: expect.stringContaining(`**Comments**\n___\n comment 1 for DESCRIPTION line 1\n comment 1 for DESCRIPTION line 2\n\nSource: ${DUMMY_URI_TRIMMED} \`L: 14\`\n___\n comment 2 for DESCRIPTION\n\nSource: ${DUMMY_URI_TRIMMED} \`L: 16\``)
value: expect.stringContaining(` comment 1 for custom variable MYVAR\n\nSource: ${DUMMY_URI_TRIMMED} \`L: 15\`\n___\n comment 2 for custom variable MYVAR\n\nSource: ${DUMMY_URI_TRIMMED} \`L: 17\`\n___\n comment 1 for MYVAR in bar.inc\n\nSource: ${FIXTURE_DOCUMENT.BAR_INC.uri.replace('file://', '')} \`L: 5\``)
})
})
)

// show comments for custom variable and comments for this variable from the include file
// show comments for custom function
expect(shouldShow2).toEqual(
expect.objectContaining({
contents: expect.objectContaining({
value: expect.stringContaining(`**Comments**\n___\n comment 1 for custom variable MYVAR\n\nSource: ${DUMMY_URI_TRIMMED} \`L: 18\`\n___\n comment 1 for MYVAR in bar.inc\n\nSource: ${FIXTURE_DOCUMENT.BAR_INC.uri.replace('file://', '')} \`L: 5\``)
value: expect.stringContaining(` comment 1 for my_func\n\nSource: ${DUMMY_URI_TRIMMED} \`L: 23\``)
})
})
)
// Don't show comments for variables/tasks that already have docs from yocto/bitbake

// show comments for yocto task
expect(shouldShow3).toEqual(
expect(shouldNotShow1).not.toEqual(
expect.objectContaining({
contents: expect.objectContaining({
value: expect.stringContaining(`**Comments**\n___\n comment 1 for do_build\n\nSource: ${DUMMY_URI_TRIMMED} \`L: 20\``)
value: expect.stringContaining(`comment 1 for my_func\n\nSource: ${DUMMY_URI_TRIMMED} \`L: 23\``)
})
})
)

// show comments for custom function
expect(shouldShow4).toEqual(
expect(shouldNotShow2).not.toEqual(
expect.objectContaining({
contents: expect.objectContaining({
value: expect.stringContaining(`**Comments**\n___\n comment 1 for my_func\n\nSource: ${DUMMY_URI_TRIMMED} \`L: 24\``)
value: expect.stringContaining(`comment 1 for do_build\n\nSource: ${DUMMY_URI_TRIMMED} \`L: 19\``)
})
})
)
Expand Down
8 changes: 6 additions & 2 deletions server/src/connectionHandlers/onHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ export async function onHoverHandler (params: HoverParams): Promise<Hover | null
}

const comments = getGlobalSymbolComments(textDocument.uri, word)
hoverValue += comments ?? ''

// Append comments for variables or tasks that don't have documentation from Yocto/BitBake
if (hoverValue === '' && comments !== null) {
hoverValue += comments ?? ''
}

if (hoverValue !== '') {
const hover: Hover = {
Expand All @@ -102,7 +106,7 @@ function getGlobalSymbolComments (uri: string, word: string): string | null {
if (symbolComments[word] !== undefined) {
const allCommentsForSymbol = symbolComments[word]
if (allCommentsForSymbol.length > 0) {
return `\n___\n**Comments**\n___\n${allCommentsForSymbol.map((item) => item.comments.map(comment => comment.slice(1)).join('\n') + `\n\nSource: ${item.uri.replace('file://', '')} \`L: ${item.line + 1}\``).join('\n___\n')}`
return `${allCommentsForSymbol.map((item) => item.comments.map(comment => comment.slice(1)).join('\n') + `\n\nSource: ${item.uri.replace('file://', '')} \`L: ${item.line + 1}\``).join('\n___\n')}`
}
}
}
Expand Down

0 comments on commit 3d76325

Please sign in to comment.