Skip to content

Commit

Permalink
Improve IntelliSense with json parameters (#663)
Browse files Browse the repository at this point in the history
- Json parameters should do completion of the full "parameter name"
instead of the prefix.
- Optimize type-unions that are only string literals into string-unions
when parsing (also bump the cache version to invalidate)
- Shell output message container is hidden when first created.
  • Loading branch information
curtisman authored Feb 4, 2025
1 parent 0a1eb2b commit 2827134
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
12 changes: 11 additions & 1 deletion ts/packages/actionSchema/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,18 @@ class ActionParser {
};
}

private parseTypeUnionType(node: ts.UnionTypeNode): SchemaTypeUnion {
private parseTypeUnionType(
node: ts.UnionTypeNode,
): SchemaTypeUnion | SchemaTypeStringUnion {
const types = node.types.map((type) => this.parseType(type));
if (types.every((type) => type.type === "string-union")) {
return {
type: "string-union",
typeEnum: types
.map((type) => (type as SchemaTypeStringUnion).typeEnum)
.flat(),
};
}
return {
type: "type-union",
types,
Expand Down
16 changes: 12 additions & 4 deletions ts/packages/dispatcher/src/command/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,18 @@ function getPendingFlag(
}
const lastToken = params.tokens[params.tokens.length - 1];
const resolvedFlag = resolveFlag(flags, lastToken);
return resolvedFlag !== undefined &&
getFlagType(resolvedFlag[1]) !== "boolean"
? `--${resolvedFlag[0]}` // use the full flag name in case it was a short flag
: undefined;
if (resolvedFlag === undefined) {
return undefined;
}
const type = getFlagType(resolvedFlag[1]);
if (type === "boolean") {
return undefined;
}
if (type === "json") {
return `${lastToken}`;
}

return `--${resolvedFlag[0]}`; // use the full flag name in case it was a short flag
}

async function getCommandParameterCompletion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function hashStrings(...str: string[]) {
return hash.digest("base64");
}

const ActionSchemaFileCacheVersion = 1;
const ActionSchemaFileCacheVersion = 2;
type ActionSchemaFileCacheJSON = {
version: number;
entries: [string, ActionSchemaFileJSON][];
Expand Down
3 changes: 3 additions & 0 deletions ts/packages/shell/src/renderer/src/messageContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ export class MessageContainer {
this.div = div;

this.updateSource();

// Don't show initialize without any messages.
this.hide();
}

public getMessage() {
Expand Down

0 comments on commit 2827134

Please sign in to comment.