Skip to content

Commit

Permalink
more type info on completions
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewNolte committed Nov 3, 2024
1 parent 6413927 commit 042ca57
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/analysis/CtagsServerComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class CtagsServerComponent
async provideCompletionItems(
document: vscode.TextDocument,
position: vscode.Position,
_token: vscode.CancellationToken,
token: vscode.CancellationToken,
context: vscode.CompletionContext
): Promise<vscode.CompletionItem[]> {
let prevChar = getPrevChar(document, position)
Expand All @@ -133,7 +133,7 @@ export class CtagsServerComponent
const moduleCompletions = await this.provideModuleCompletion(
document,
position,
_token,
token,
context
)
this.logger.info(`Returning ${moduleCompletions.length} module completions`)
Expand Down Expand Up @@ -172,7 +172,7 @@ export class CtagsServerComponent
return []
}
symbols = await ctags.getPackageSymbols()
this.logger.info(`Found ${symbols.length} completions in package`)
this.logger.info(`Found ${symbols.length} completions in package ${pkgName}`)
} else if (context.triggerCharacter === '.') {
let parentScope = getParentText(document, new vscode.Range(position, position))

Expand Down
22 changes: 18 additions & 4 deletions src/analysis/Symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export class Symbol {
},
this.getCompletionItemKind()
)
if (!(this.type === 'typedef' || this.type === 'instance')) {
if (!(this.type === 'instance')) {
let md = new vscode.MarkdownString()
md.appendCodeblock(this.getHoverText(), 'systemverilog')
item.documentation = md
Expand All @@ -328,19 +328,33 @@ export class Symbol {
}

public getTypeInfo(): string {
// maybe one day ctags will have these
if (this.type === 'port') {
const hover = this.getHoverText()
return hover.substring(0, hover.indexOf(this.name) - 1)
} else if (this.type === 'parameter') {
return getAssignment(this.doc.getText(this.getFullRange()), this.name, 'parameter')
} else if (this.type === 'constant') {
// enum case
// enum child case
if (this.parentType === 'typedef') {
return this.parentScope.split('.').at(-1) ?? ''
}
const text = this.doc.getText(this.getFullRange())

// localparam case
return getAssignment(this.doc.getText(this.getFullRange()), this.name, 'localparam')
if (text.includes('localparam')) {
return getAssignment(text, this.name, 'localparam')
} else if (text.includes('parameter')) {
return getAssignment(text, this.name, 'parameter')
}
} else if (this.type === 'typedef') {
const text = this.doc.getText(this.getFullRange())
const assign = getAssignment(text, this.name, 'typedef')
if (assign.startsWith('enum')) {
return 'enum'
} else if (assign.startsWith('struct')) {
return 'struct'
}
return 'typedef ' + assign
}
return this.typeRef ?? this.type
}
Expand Down

0 comments on commit 042ca57

Please sign in to comment.