Skip to content

Commit

Permalink
Include field documentation in autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
misode committed Dec 12, 2024
1 parent e90712c commit 7ed24bd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/json/src/completer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const object = core.completer.record<JsonStringNode, JsonNode, JsonObjectNode>({
core.CompletionItem.create(key, pair?.key ?? range, {
kind: core.CompletionKind.Field,
detail: mcdoc.McdocType.toString(field.type as core.Mutable<mcdoc.McdocType>),
documentation: field.desc,
deprecated: field.deprecated,
sortText: field.optional ? '$b' : '$a', // sort above hardcoded $schema
filterText: `"${key}"`,
Expand Down Expand Up @@ -83,11 +84,14 @@ function getValues(
ctx: core.CompleterContext,
): core.CompletionItem[] {
return mcdoc.runtime.completer.getValues(typeDef, ctx)
.map(({ value, labelSuffix, detail, kind, completionKind, insertText, sortText }) =>
.map((
{ value, labelSuffix, detail, documentation, kind, completionKind, insertText, sortText },
) =>
core.CompletionItem.create(value, range, {
kind: completionKind ?? core.CompletionKind.Value,
labelSuffix,
detail,
documentation,
filterText: kind === 'string' ? `"${value}"` : value,
insertText: kind === 'string' ? `"${insertText ?? value}"` : insertText ?? value,
sortText,
Expand Down
2 changes: 1 addition & 1 deletion packages/language-server/src/util/toLS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export function completionItem(
kind: completion.kind,
...(completion.labelSuffix ? { labelDetails: { detail: completion.labelSuffix } } : {}),
detail: completion.detail,
documentation: completion.documentation,
documentation: completion.documentation ? markupContent(completion.documentation) : undefined,
filterText: completion.filterText,
sortText: completion.sortText,
textEdit,
Expand Down
2 changes: 2 additions & 0 deletions packages/mcdoc/src/runtime/completer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function getFields(
export type SimpleCompletionValue = {
value: string
detail?: string
documentation?: string
labelSuffix?: string
kind?: McdocType['kind']
completionKind?: core.CompletionKind
Expand Down Expand Up @@ -131,6 +132,7 @@ export function getValues(
value: `${v.value}`,
detail: v.identifier,
kind: typeDef.enumKind ?? 'string',
documentation: v.desc,
}))
case 'byte':
case 'short':
Expand Down
7 changes: 6 additions & 1 deletion packages/nbt/src/completer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const compound = core.completer.record<NbtStringNode, NbtNode, NbtCompoundNode>(
core.CompletionItem.create(key, pair?.key ?? range, {
kind: core.CompletionKind.Field,
detail: mcdoc.McdocType.toString(field.type as core.Mutable<mcdoc.McdocType>),
documentation: field.desc,
deprecated: field.deprecated,
sortText: field.optional ? '$b' : '$a', // sort above hardcoded $schema
filterText: formatKey(key, pair?.key?.quote),
Expand Down Expand Up @@ -126,6 +127,7 @@ function getPathKeys(
core.CompletionItem.create(key, range, {
kind: core.CompletionKind.Field,
detail: mcdoc.McdocType.toString(field.type as core.Mutable<mcdoc.McdocType>),
documentation: field.desc,
deprecated: field.deprecated,
sortText: field.optional ? '$b' : '$a', // sort above hardcoded $schema
filterText: formatKey(key, quote),
Expand All @@ -140,11 +142,14 @@ function getValues(
ctx: mcdoc.runtime.completer.McdocCompleterContext,
): core.CompletionItem[] {
return mcdoc.runtime.completer.getValues(typeDef, ctx)
.map(({ value, labelSuffix, detail, kind, completionKind, insertText, sortText }) =>
.map((
{ value, labelSuffix, detail, documentation, kind, completionKind, insertText, sortText },
) =>
core.CompletionItem.create(value, range, {
kind: completionKind ?? core.CompletionKind.Value,
labelSuffix,
detail,
documentation,
filterText: formatValue(value, kind),
insertText: formatValue(insertText ?? value, kind),
sortText,
Expand Down

0 comments on commit 7ed24bd

Please sign in to comment.