Skip to content
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
1 change: 1 addition & 0 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ const enumDefs = [
{ name: "ModifierFlags", goPrefix: "ModifierFlags", goFile: "internal/ast/modifierflags.go", outDir: "_packages/native-preview/src/enums" },
{ name: "TokenFlags", goPrefix: "TokenFlags", goFile: "internal/ast/tokenflags.go", outDir: "_packages/native-preview/src/enums" },
{ name: "NodeBuilderFlags", goPrefix: "Flags", goFile: "internal/nodebuilder/types.go", outDir: "_packages/native-preview/src/enums" },
{ name: "CompletionItemKind", goPrefix: "CompletionItemKind", goFile: "internal/lsp/lsproto/lsp_generated.go", outDir: "_packages/native-preview/src/enums" },
];

/**
Expand Down
28 changes: 26 additions & 2 deletions _packages/native-preview/src/api/async/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference path="../node/node.ts" preserve="true" />
import { CompletionItemKind } from "#enums/completionItemKind";
import { DiagnosticCategory } from "#enums/diagnosticCategory";
import { ElementFlags } from "#enums/elementFlags";
import { NodeBuilderFlags } from "#enums/nodeBuilderFlags";
Expand Down Expand Up @@ -40,6 +41,7 @@ import {
toPath,
} from "../path.ts";
import type {
CompletionInfoResponse,
ConfigResponse,
DocumentIdentifier,
DocumentPosition,
Expand All @@ -65,6 +67,9 @@ import {
import type {
AssertsIdentifierTypePredicate,
AssertsThisTypePredicate,
CompletionEntry,
CompletionInfo,
CompletionOptions,
ConditionalType,
Diagnostic,
FreshableType,
Expand All @@ -91,9 +96,9 @@ import type {
UnionType,
} from "./types.ts";

export { DiagnosticCategory, ElementFlags, ModifierFlags, NodeBuilderFlags, ObjectFlags, SignatureFlags, SignatureKind, SymbolFlags, TypeFlags, TypePredicateKind };
export { CompletionItemKind, DiagnosticCategory, ElementFlags, ModifierFlags, NodeBuilderFlags, ObjectFlags, SignatureFlags, SignatureKind, SymbolFlags, TypeFlags, TypePredicateKind };
export type { APIOptions, ClientSocketOptions, ClientSpawnOptions, DocumentIdentifier, DocumentPosition, LSPConnectionOptions };
export type { AssertsIdentifierTypePredicate, AssertsThisTypePredicate, ConditionalType, Diagnostic, FreshableType, IdentifierTypePredicate, IndexedAccessType, IndexInfo, IndexType, InterfaceType, IntersectionType, IntrinsicType, LiteralType, ObjectType, StringMappingType, SubstitutionType, TemplateLiteralType, ThisTypePredicate, TupleType, Type, TypeParameter, TypePredicate, TypePredicateBase, TypeReference, UnionOrIntersectionType, UnionType };
export type { AssertsIdentifierTypePredicate, AssertsThisTypePredicate, CompletionEntry, CompletionInfo, CompletionOptions, ConditionalType, Diagnostic, FreshableType, IdentifierTypePredicate, IndexedAccessType, IndexInfo, IndexType, InterfaceType, IntersectionType, IntrinsicType, LiteralType, ObjectType, StringMappingType, SubstitutionType, TemplateLiteralType, ThisTypePredicate, TupleType, Type, TypeParameter, TypePredicate, TypePredicateBase, TypeReference, UnionOrIntersectionType, UnionType };
export { documentURIToFileName, fileNameToDocumentURI } from "../path.ts";

/** Type alias for the snapshot-scoped object registry */
Expand Down Expand Up @@ -578,6 +583,25 @@ export class Checker {
}));
}

async getCompletionsAtPosition(document: string, position: number, options?: CompletionOptions): Promise<CompletionInfo | undefined> {
const data = await this.client.apiRequest<CompletionInfoResponse | null>("getCompletionsAtPosition", {
snapshot: this.snapshotId,
project: this.projectId,
file: document,
position,
triggerCharacter: options?.triggerCharacter,
includeSymbol: options?.includeSymbol,
});
if (!data) return undefined;
return {
isIncomplete: data.isIncomplete,
entries: data.entries.map(e => ({
...e,
symbol: e.symbol ? this.objectRegistry.getOrCreateSymbol(e.symbol) : undefined,
})),
};
}

getTypeAtLocation(node: Node): Promise<Type | undefined>;
getTypeAtLocation(nodes: readonly Node[]): Promise<(Type | undefined)[]>;
async getTypeAtLocation(nodeOrNodes: Node | readonly Node[]): Promise<Type | (Type | undefined)[] | undefined> {
Expand Down
32 changes: 32 additions & 0 deletions _packages/native-preview/src/api/async/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { CompletionItemKind } from "#enums/completionItemKind";
import type { DiagnosticCategory } from "#enums/diagnosticCategory";
import type { ElementFlags } from "#enums/elementFlags";
import type { ObjectFlags } from "#enums/objectFlags";
Expand Down Expand Up @@ -205,6 +206,37 @@ export interface IndexInfo {
readonly declaration?: NodeHandle;
}

export interface CompletionEntryLabelDetails {
detail?: string;
description?: string;
}

/** Options for {@link Checker.getCompletionsAtPosition}. */
export interface CompletionOptions {
Comment thread
piotrtomiak marked this conversation as resolved.
triggerCharacter?: string;
/** Include a `symbol` property on each completion entry. Only populated for symbol-based completions (not keywords or literals). */
includeSymbol?: boolean;
}

/** A single completion item returned by {@link Checker.getCompletionsAtPosition}. */
export interface CompletionEntry {
readonly name: string;
readonly kind?: CompletionItemKind;
readonly sortText?: string;
readonly insertText?: string;
readonly filterText?: string;
readonly detail?: string;
readonly labelDetails?: CompletionEntryLabelDetails;
/** The symbol associated with this completion entry. Only set when `includeSymbol: true` is passed and a symbol is available. */
readonly symbol?: Symbol;
}

/** The result of {@link Checker.getCompletionsAtPosition}. */
export interface CompletionInfo {
readonly isIncomplete: boolean;
readonly entries: readonly CompletionEntry[];
}

/**
* A diagnostic message from the TypeScript compiler.
*/
Expand Down
22 changes: 22 additions & 0 deletions _packages/native-preview/src/api/proto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { CompletionItemKind } from "#enums/completionItemKind";
import {
documentURIToFileName,
fileNameToDocumentURI,
Expand Down Expand Up @@ -194,3 +195,24 @@ export interface ProfileParams {
export interface ProfileResult {
file: string;
}

export interface CompletionEntryLabelDetailsResponse {
detail?: string;
description?: string;
}

export interface CompletionEntryResponse {
name: string;
kind?: CompletionItemKind;
sortText?: string;
insertText?: string;
filterText?: string;
detail?: string;
labelDetails?: CompletionEntryLabelDetailsResponse;
symbol?: SymbolResponse;
}

export interface CompletionInfoResponse {
isIncomplete: boolean;
entries: CompletionEntryResponse[];
}
28 changes: 26 additions & 2 deletions _packages/native-preview/src/api/sync/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// Regenerate: npm run generate (from _packages/native-preview)
//
/// <reference path="../node/node.ts" preserve="true" />
import { CompletionItemKind } from "#enums/completionItemKind";
import { DiagnosticCategory } from "#enums/diagnosticCategory";
import { ElementFlags } from "#enums/elementFlags";
import { NodeBuilderFlags } from "#enums/nodeBuilderFlags";
Expand Down Expand Up @@ -48,6 +49,7 @@ import {
toPath,
} from "../path.ts";
import type {
CompletionInfoResponse,
ConfigResponse,
DocumentIdentifier,
DocumentPosition,
Expand All @@ -73,6 +75,9 @@ import {
import type {
AssertsIdentifierTypePredicate,
AssertsThisTypePredicate,
CompletionEntry,
CompletionInfo,
CompletionOptions,
ConditionalType,
Diagnostic,
FreshableType,
Expand All @@ -99,9 +104,9 @@ import type {
UnionType,
} from "./types.ts";

export { DiagnosticCategory, ElementFlags, ModifierFlags, NodeBuilderFlags, ObjectFlags, SignatureFlags, SignatureKind, SymbolFlags, TypeFlags, TypePredicateKind };
export { CompletionItemKind, DiagnosticCategory, ElementFlags, ModifierFlags, NodeBuilderFlags, ObjectFlags, SignatureFlags, SignatureKind, SymbolFlags, TypeFlags, TypePredicateKind };
export type { APIOptions, ClientSocketOptions, ClientSpawnOptions, DocumentIdentifier, DocumentPosition, LSPConnectionOptions };
export type { AssertsIdentifierTypePredicate, AssertsThisTypePredicate, ConditionalType, Diagnostic, FreshableType, IdentifierTypePredicate, IndexedAccessType, IndexInfo, IndexType, InterfaceType, IntersectionType, IntrinsicType, LiteralType, ObjectType, StringMappingType, SubstitutionType, TemplateLiteralType, ThisTypePredicate, TupleType, Type, TypeParameter, TypePredicate, TypePredicateBase, TypeReference, UnionOrIntersectionType, UnionType };
export type { AssertsIdentifierTypePredicate, AssertsThisTypePredicate, CompletionEntry, CompletionInfo, CompletionOptions, ConditionalType, Diagnostic, FreshableType, IdentifierTypePredicate, IndexedAccessType, IndexInfo, IndexType, InterfaceType, IntersectionType, IntrinsicType, LiteralType, ObjectType, StringMappingType, SubstitutionType, TemplateLiteralType, ThisTypePredicate, TupleType, Type, TypeParameter, TypePredicate, TypePredicateBase, TypeReference, UnionOrIntersectionType, UnionType };
export { documentURIToFileName, fileNameToDocumentURI } from "../path.ts";

/** Type alias for the snapshot-scoped object registry */
Expand Down Expand Up @@ -586,6 +591,25 @@ export class Checker {
}));
}

getCompletionsAtPosition(document: string, position: number, options?: CompletionOptions): CompletionInfo | undefined {
const data = this.client.apiRequest<CompletionInfoResponse | null>("getCompletionsAtPosition", {
snapshot: this.snapshotId,
project: this.projectId,
file: document,
position,
triggerCharacter: options?.triggerCharacter,
includeSymbol: options?.includeSymbol,
});
if (!data) return undefined;
return {
isIncomplete: data.isIncomplete,
entries: data.entries.map(e => ({
...e,
symbol: e.symbol ? this.objectRegistry.getOrCreateSymbol(e.symbol) : undefined,
})),
};
}

getTypeAtLocation(node: Node): Type | undefined;
getTypeAtLocation(nodes: readonly Node[]): (Type | undefined)[];
getTypeAtLocation(nodeOrNodes: Node | readonly Node[]): Type | (Type | undefined)[] | undefined {
Expand Down
32 changes: 32 additions & 0 deletions _packages/native-preview/src/api/sync/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Source: src/api/async/types.ts
// Regenerate: npm run generate (from _packages/native-preview)
//
import type { CompletionItemKind } from "#enums/completionItemKind";
Comment thread
piotrtomiak marked this conversation as resolved.
import type { DiagnosticCategory } from "#enums/diagnosticCategory";
import type { ElementFlags } from "#enums/elementFlags";
import type { ObjectFlags } from "#enums/objectFlags";
Expand Down Expand Up @@ -213,6 +214,37 @@ export interface IndexInfo {
readonly declaration?: NodeHandle;
}

export interface CompletionEntryLabelDetails {
detail?: string;
description?: string;
}

/** Options for {@link Checker.getCompletionsAtPosition}. */
export interface CompletionOptions {
Comment thread
piotrtomiak marked this conversation as resolved.
triggerCharacter?: string;
/** Include a `symbol` property on each completion entry. Only populated for symbol-based completions (not keywords or literals). */
includeSymbol?: boolean;
}

/** A single completion item returned by {@link Checker.getCompletionsAtPosition}. */
export interface CompletionEntry {
readonly name: string;
readonly kind?: CompletionItemKind;
readonly sortText?: string;
readonly insertText?: string;
readonly filterText?: string;
readonly detail?: string;
readonly labelDetails?: CompletionEntryLabelDetails;
/** The symbol associated with this completion entry. Only set when `includeSymbol: true` is passed and a symbol is available. */
readonly symbol?: Symbol;
}

/** The result of {@link Checker.getCompletionsAtPosition}. */
export interface CompletionInfo {
readonly isIncomplete: boolean;
readonly entries: readonly CompletionEntry[];
}

/**
* A diagnostic message from the TypeScript compiler.
*/
Expand Down
29 changes: 29 additions & 0 deletions _packages/native-preview/src/enums/completionItemKind.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Code generated by Herebyfile.mjs generate:enums from internal/lsp/lsproto/lsp_generated.go. DO NOT EDIT.

export enum CompletionItemKind {
Text = 1,
Method = 2,
Function = 3,
Constructor = 4,
Field = 5,
Variable = 6,
Class = 7,
Interface = 8,
Module = 9,
Property = 10,
Unit = 11,
Value = 12,
Enum = 13,
Keyword = 14,
Snippet = 15,
Color = 16,
File = 17,
Reference = 18,
Folder = 19,
EnumMember = 20,
Constant = 21,
Struct = 22,
Event = 23,
Operator = 24,
TypeParameter = 25,
}
29 changes: 29 additions & 0 deletions _packages/native-preview/src/enums/completionItemKind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Code generated by Herebyfile.mjs generate:enums from internal/lsp/lsproto/lsp_generated.go. DO NOT EDIT.
export var CompletionItemKind: any;
(function (CompletionItemKind) {
CompletionItemKind[CompletionItemKind["Text"] = 1] = "Text";
CompletionItemKind[CompletionItemKind["Method"] = 2] = "Method";
CompletionItemKind[CompletionItemKind["Function"] = 3] = "Function";
CompletionItemKind[CompletionItemKind["Constructor"] = 4] = "Constructor";
CompletionItemKind[CompletionItemKind["Field"] = 5] = "Field";
CompletionItemKind[CompletionItemKind["Variable"] = 6] = "Variable";
CompletionItemKind[CompletionItemKind["Class"] = 7] = "Class";
CompletionItemKind[CompletionItemKind["Interface"] = 8] = "Interface";
CompletionItemKind[CompletionItemKind["Module"] = 9] = "Module";
CompletionItemKind[CompletionItemKind["Property"] = 10] = "Property";
CompletionItemKind[CompletionItemKind["Unit"] = 11] = "Unit";
CompletionItemKind[CompletionItemKind["Value"] = 12] = "Value";
CompletionItemKind[CompletionItemKind["Enum"] = 13] = "Enum";
CompletionItemKind[CompletionItemKind["Keyword"] = 14] = "Keyword";
CompletionItemKind[CompletionItemKind["Snippet"] = 15] = "Snippet";
CompletionItemKind[CompletionItemKind["Color"] = 16] = "Color";
CompletionItemKind[CompletionItemKind["File"] = 17] = "File";
CompletionItemKind[CompletionItemKind["Reference"] = 18] = "Reference";
CompletionItemKind[CompletionItemKind["Folder"] = 19] = "Folder";
CompletionItemKind[CompletionItemKind["EnumMember"] = 20] = "EnumMember";
CompletionItemKind[CompletionItemKind["Constant"] = 21] = "Constant";
CompletionItemKind[CompletionItemKind["Struct"] = 22] = "Struct";
CompletionItemKind[CompletionItemKind["Event"] = 23] = "Event";
CompletionItemKind[CompletionItemKind["Operator"] = 24] = "Operator";
CompletionItemKind[CompletionItemKind["TypeParameter"] = 25] = "TypeParameter";
})(CompletionItemKind || (CompletionItemKind = {}));
Loading
Loading