Skip to content

Commit 003823e

Browse files
committed
track position kind of completion to control completion suppression more finely.
1 parent 9426caa commit 003823e

File tree

4 files changed

+87
-24
lines changed

4 files changed

+87
-24
lines changed

src/core/lib/yaml-intelligence/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Schema } from "../yaml-schema/types.ts";
99
import { MappedString } from "../text-types.ts";
1010

1111
export type AutomationKind = "validation" | "completions";
12+
export type PositionKind = "code-cell" | "metadata";
1213

1314
export interface YamlIntelligenceContext {
1415
code: string | MappedString;
@@ -30,6 +31,8 @@ export interface YamlIntelligenceContext {
3031
commentPrefix?: string;
3132
explicit?: boolean;
3233
client?: string;
34+
35+
positionKind?: PositionKind;
3336
}
3437

3538
export interface LocateFromIndentationContext {

src/core/lib/yaml-intelligence/yaml-intelligence.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
*
66
*/
77

8-
import { AutomationKind, YamlIntelligenceContext } from "./types.ts";
8+
import {
9+
AutomationKind,
10+
PositionKind,
11+
YamlIntelligenceContext,
12+
} from "./types.ts";
913

1014
import { buildTreeSitterAnnotation, locateCursor } from "./annotated-yaml.ts";
1115

@@ -83,6 +87,7 @@ interface CompletionContext {
8387
commentPrefix: string;
8488
context: IDEContext;
8589
completionPosition?: "key" | "value";
90+
positionKind: PositionKind;
8691
}
8792

8893
interface ValidationResult {
@@ -249,6 +254,8 @@ async function completionsFromGoodParseYAML(context: YamlIntelligenceContext) {
249254
schema, // schema of yaml object
250255
} = context;
251256

257+
const positionKind = context.positionKind || "metadata";
258+
252259
// if this is a yaml inside a language chunk, it will have a
253260
// comment prefix which we need to know about in order to
254261
// autocomplete linebreaks correctly.
@@ -273,6 +280,7 @@ async function completionsFromGoodParseYAML(context: YamlIntelligenceContext) {
273280
commentPrefix,
274281
context,
275282
completionPosition: "key",
283+
positionKind,
276284
});
277285
return rawCompletions;
278286
}
@@ -301,6 +309,7 @@ async function completionsFromGoodParseYAML(context: YamlIntelligenceContext) {
301309
commentPrefix,
302310
context,
303311
completionPosition: "key",
312+
positionKind,
304313
});
305314
return rawCompletions;
306315
};
@@ -396,6 +405,7 @@ async function completionsFromGoodParseYAML(context: YamlIntelligenceContext) {
396405
: completionOnArraySequence // this picks up case 5 (and 1, but case one was already handled.)
397406
? "key"
398407
: undefined,
408+
positionKind,
399409
});
400410
// never followup a suggestion in value position
401411
if (completionOnValuePosition) {
@@ -444,16 +454,20 @@ function uniqBy<T>(lst: T[], keyFun: (item: T) => (string | undefined)): T[] {
444454
}
445455

446456
// Currently, the only special case we have is for "execute-only" tags
447-
// in paths that don't start with execute.
457+
// in paths that don't start with execute in yaml metadata completions
448458
function dropCompletionsFromSchema(
449459
obj: CompletionContext,
450460
completion: Completion,
451461
) {
452462
const matchingSchema = resolveSchema(completion.schema!);
453463
const {
454464
path,
465+
positionKind,
455466
} = obj;
456467

468+
if (positionKind === "code-cell") {
469+
return false;
470+
}
457471
if (completion.type === "value") {
458472
return false;
459473
}
@@ -815,6 +829,7 @@ async function automationFromGoodParseMarkdown(
815829
schema,
816830
code: foundCell.source,
817831
schemaName: "front-matter",
832+
positionKind: "metadata",
818833
};
819834
// user asked for autocomplete on "---": report none
820835
if (positionInTicks(context)) {
@@ -840,6 +855,7 @@ async function automationFromGoodParseMarkdown(
840855
column: position.column,
841856
},
842857
line,
858+
positionKind: "code-cell",
843859
});
844860
} else {
845861
// do not complete what we do not understand
@@ -862,6 +878,7 @@ async function automationFromGoodParseMarkdown(
862878
schemaName: "front-matter",
863879
line,
864880
position, // we don't need to adjust position because front matter only shows up at start of file.
881+
positionKind: "metadata",
865882
}),
866883
) as ValidationResult[];
867884
lints.push(...innerLints);
@@ -882,6 +899,7 @@ async function automationFromGoodParseMarkdown(
882899
...position,
883900
row: position.row - (linesSoFar + 1),
884901
},
902+
positionKind: "code-cell",
885903
}) as ValidationResult[];
886904
lints.push(...innerLints);
887905
}
@@ -1002,9 +1020,15 @@ async function automationFileTypeDispatch(
10021020
case "markdown":
10031021
return automationFromGoodParseMarkdown(kind, context);
10041022
case "yaml":
1005-
return automationFromGoodParseYAML(kind, context);
1023+
return automationFromGoodParseYAML(kind, {
1024+
...context,
1025+
positionKind: "metadata",
1026+
});
10061027
case "script":
1007-
return automationFromGoodParseScript(kind, context);
1028+
return automationFromGoodParseScript(kind, {
1029+
...context,
1030+
positionKind: "code-cell",
1031+
});
10081032
default:
10091033
return null;
10101034
}

src/resources/editor/tools/vs-code.mjs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28175,6 +28175,7 @@ async function completionsFromGoodParseYAML(context) {
2817528175
position,
2817628176
schema: schema2
2817728177
} = context;
28178+
const positionKind = context.positionKind || "metadata";
2817828179
const commentPrefix = context.commentPrefix || "";
2817928180
const parser = await getTreeSitter();
2818028181
let word = "";
@@ -28191,7 +28192,8 @@ async function completionsFromGoodParseYAML(context) {
2819128192
indent: indent2,
2819228193
commentPrefix,
2819328194
context,
28194-
completionPosition: "key"
28195+
completionPosition: "key",
28196+
positionKind
2819528197
});
2819628198
return rawCompletions;
2819728199
}
@@ -28212,7 +28214,8 @@ async function completionsFromGoodParseYAML(context) {
2821228214
indent,
2821328215
commentPrefix,
2821428216
context,
28215-
completionPosition: "key"
28217+
completionPosition: "key",
28218+
positionKind
2821628219
});
2821728220
return rawCompletions;
2821828221
};
@@ -28263,7 +28266,8 @@ async function completionsFromGoodParseYAML(context) {
2826328266
indent,
2826428267
commentPrefix,
2826528268
context,
28266-
completionPosition: completionOnValuePosition ? "value" : completionOnArraySequence ? "key" : void 0
28269+
completionPosition: completionOnValuePosition ? "value" : completionOnArraySequence ? "key" : void 0,
28270+
positionKind
2826728271
});
2826828272
if (completionOnValuePosition) {
2826928273
rawCompletions.completions = rawCompletions.completions.map((c) => ({
@@ -28298,8 +28302,12 @@ function uniqBy(lst, keyFun) {
2829828302
function dropCompletionsFromSchema(obj, completion) {
2829928303
const matchingSchema = resolveSchema(completion.schema);
2830028304
const {
28301-
path
28305+
path,
28306+
positionKind
2830228307
} = obj;
28308+
if (positionKind === "code-cell") {
28309+
return false;
28310+
}
2830328311
if (completion.type === "value") {
2830428312
return false;
2830528313
}
@@ -28545,7 +28553,8 @@ async function automationFromGoodParseMarkdown(kind, context) {
2854528553
position,
2854628554
schema: schema2,
2854728555
code: foundCell.source,
28548-
schemaName: "front-matter"
28556+
schemaName: "front-matter",
28557+
positionKind: "metadata"
2854928558
};
2855028559
if (positionInTicks(context)) {
2855128560
return noCompletions;
@@ -28565,7 +28574,8 @@ async function automationFromGoodParseMarkdown(kind, context) {
2856528574
row: position.row - foundCell.cellStartLine,
2856628575
column: position.column
2856728576
},
28568-
line
28577+
line,
28578+
positionKind: "code-cell"
2856928579
});
2857028580
} else {
2857128581
return noCompletions;
@@ -28582,7 +28592,8 @@ async function automationFromGoodParseMarkdown(kind, context) {
2858228592
schema: await getFrontMatterSchema(),
2858328593
schemaName: "front-matter",
2858428594
line,
28585-
position
28595+
position,
28596+
positionKind: "metadata"
2858628597
}));
2858728598
lints.push(...innerLints);
2858828599
} else if (cell.cell_type === "markdown" || cell.cell_type === "math") {
@@ -28600,7 +28611,8 @@ async function automationFromGoodParseMarkdown(kind, context) {
2860028611
position: {
2860128612
...position,
2860228613
row: position.row - (linesSoFar + 1)
28603-
}
28614+
},
28615+
positionKind: "code-cell"
2860428616
});
2860528617
lints.push(...innerLints);
2860628618
}
@@ -28673,9 +28685,15 @@ async function automationFileTypeDispatch(filetype, kind, context) {
2867328685
case "markdown":
2867428686
return automationFromGoodParseMarkdown(kind, context);
2867528687
case "yaml":
28676-
return automationFromGoodParseYAML(kind, context);
28688+
return automationFromGoodParseYAML(kind, {
28689+
...context,
28690+
positionKind: "metadata"
28691+
});
2867728692
case "script":
28678-
return automationFromGoodParseScript(kind, context);
28693+
return automationFromGoodParseScript(kind, {
28694+
...context,
28695+
positionKind: "code-cell"
28696+
});
2867928697
default:
2868028698
return null;
2868128699
}

src/resources/editor/tools/yaml/web-worker.js

Lines changed: 28 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)