Skip to content

Commit

Permalink
Feat: Add a config to enable or disable codeLens on function references
Browse files Browse the repository at this point in the history
  • Loading branch information
WilsonZiweiWang committed Apr 30, 2024
1 parent 8395fc3 commit ae1a255
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@
"type": "boolean",
"default": false,
"description": "Turn on this setting to stop this extension from modifying the VS Code configuration of the workspace. Note that this will also disable some features related to embedded Python and Shell code."
},
"bitbake.enableCodeLensReferencesOnFunctions": {
"type": "boolean",
"default": false,
"description": "Enable or disable the CodeLens references for functions in BitBake files."
}
}
},
Expand Down
9 changes: 7 additions & 2 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ setDefinitionsConnection(connection)
const documents = new TextDocuments<TextDocument>(TextDocument)
let workspaceFolder: string | undefined
let pokyFolder: string | undefined

let enableCodeLensReferencesOnFunctions: boolean = false
const disposables: Disposable[] = []

let currentActiveTextDocument: TextDocument = TextDocument.create(
Expand Down Expand Up @@ -118,6 +118,7 @@ disposables.push(

connection.onDidChangeConfiguration((change) => {
logger.level = change.settings.bitbake?.loggingLevel ?? logger.level
enableCodeLensReferencesOnFunctions = change.settings.bitbake?.enableCodeLensReferencesOnFunctions ?? enableCodeLensReferencesOnFunctions
const bitbakeFolder = expandSettingPath(change.settings.bitbake?.pathToBitbakeFolder, { workspaceFolder })
if (bitbakeFolder !== undefined) {
pokyFolder = path.join(bitbakeFolder, '..') // We assume BitBake is into Poky
Expand Down Expand Up @@ -155,7 +156,11 @@ disposables.push(
connection.onCodeLens(async (params): Promise<LSP.CodeLens[]> => {
const codeLenses: LSP.CodeLens[] = []
const uri = params.textDocument.uri
// TODO: check the setting to see if showing the references code lens is allowed

if (!enableCodeLensReferencesOnFunctions) {
return []
}

const allSymbols = analyzer.getGlobalDeclarationSymbolsForUri(uri)
allSymbols.forEach((symbol) => {
if (symbol.kind === LSP.SymbolKind.Function) {
Expand Down

0 comments on commit ae1a255

Please sign in to comment.