55*
66*/
77
8- import { AutomationKind , YamlIntelligenceContext } from "./types.ts" ;
8+ import {
9+ AutomationKind ,
10+ PositionKind ,
11+ YamlIntelligenceContext ,
12+ } from "./types.ts" ;
913
1014import { 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
8893interface 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
448458function 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 }
0 commit comments