Skip to main content
Module

x/libclang/mod.ts>CXCodeCompleteResults

Deno FFI bindings for libclang
Go to Latest
class CXCodeCompleteResults
import { CXCodeCompleteResults } from "https://deno.land/x/libclang@1.0.0-beta.8/mod.ts";

Contains the results of code-completion.

This data structure contains the results of code completion, as produced by CXTranslationUnit.codeCompleteAt().

Constructors

new
CXCodeCompleteResults(tu: CXTranslationUnit, pointer: NonNullable<Deno.PointerValue>)

Properties

readonly
results: { kind: CXCursorKind; completionString: CXCompletionString; }[]

The list of possible code-completions.

Methods

dispose(): void

Free this set of code-completion results.

Calling any methods on the CXCodeCompleteResults after disposing will result in undefined behaviour. It is not strictly necessary to call this method, the memory will be released as part of JavaScript garbage collection.

getContainerKind(): { kind: CXCursorKind; incomplete: boolean; }

Returns the cursor kind for the container for this code completion context. The container is only guaranteed to be set for contexts where a container exists (i.e. member accesses or Objective-C message sends); if there is not a container, this function will return CXCursorKind.CXCursor_InvalidCode.

getContainerUSR(): string

Returns the USR (Unified Symbol Resolution) for the container for this code completion context. If there is no container for the current context, this function will return the empty string.

Determines what completions are appropriate for the context this code completion.

getDiagnostic(index: number): CXDiagnostic

Retrieve a diagnostic associated with this code completion.

getFixIt(completionIndex: number, fixitIndex: number): { fixit: string; range: CXSourceRange; }

Fix-its that must be applied before inserting the text for the corresponding completion.

By default, CXTranslationUnit#codeCompleteAt() only returns completions with empty fix-its. Extra completions with non-empty fix-its should be explicitly requested by setting CXCodeComplete_Flags.CXCodeComplete_IncludeCompletionsWithFixIts.

For the clients to be able to compute position of the cursor after applying fix-its, the following conditions are guaranteed to hold for replacement_range of the stored fix-its:

  • Ranges in the fix-its are guaranteed to never contain the completion point (or identifier under completion point, if any) inside them, except at the start or at the end of the range.
  • If a fix-it range starts or ends with completion point (or starts or ends after the identifier under completion point), it will contain at least one character. It allows to unambiguously recompute completion point after applying the fix-it.

The intuition is that provided fix-its change code around the identifier we complete, but are not allowed to touch the identifier itself or the completion point. One example of completions with corrections are the ones replacing '.' with '->' and vice versa:

Example:

std::unique_ptr<std::vector<int>> vec_ptr;
In 'vec_ptr.^', one of the completions is 'push_back', it requires
replacing '.' with '->'.
In 'vec_ptr->^', one of the completions is 'release', it requires
replacing '->' with '.'.

Determine the number of diagnostics produced prior to the location where code completion was performed.

getNumberOfFixIts(index: number): number

Retrieve the number of fix-its for the given completion index.

Calling this makes sense only if CXCodeComplete_Flags.CXCodeComplete_IncludeCompletionsWithFixIts option was set.

getObjCSelector(): string

Returns the currently-entered selector for an Objective-C message send, formatted like "initWithFoo:bar:". Only guaranteed to return a non-empty string for CXCompletionContext.CXCompletionContext_ObjCInstanceMessage and CXCompletionContext.CXCompletionContext_ObjCClassMessage.

Sort the code-completion results in case-insensitive alphabetical order. This recreates the results array.