Skip to content

Commit 2cb720f

Browse files
committed
[Pre release] fix(yaml): remove square brackets from array completions
jsonnext#162
1 parent 8941d6c commit 2cb720f

File tree

142 files changed

+7875
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+7875
-0
lines changed

cjs/constants.d.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
export declare const TOKENS: {
2+
readonly STRING: "String";
3+
readonly NUMBER: "Number";
4+
readonly TRUE: "True";
5+
readonly FALSE: "False";
6+
readonly NULL: "Null";
7+
readonly OBJECT: "Object";
8+
readonly ARRAY: "Array";
9+
readonly PROPERTY: "Property";
10+
readonly PROPERTY_NAME: "PropertyName";
11+
readonly PROPERTY_COLON: "PropertyColon";
12+
readonly ITEM: "Item";
13+
readonly JSON_TEXT: "JsonText";
14+
readonly INVALID: "⚠";
15+
};
16+
export declare const YAML_TOKENS_MAPPING: Record<
17+
string,
18+
(typeof TOKENS)[keyof typeof TOKENS]
19+
>;
20+
export declare const JSON5_TOKENS_MAPPING: Record<
21+
string,
22+
(typeof TOKENS)[keyof typeof TOKENS]
23+
>;
24+
export declare const PRIMITIVE_TYPES: (
25+
| "String"
26+
| "Number"
27+
| "True"
28+
| "False"
29+
| "Null"
30+
)[];
31+
export declare const COMPLEX_TYPES: ("Object" | "Array" | "Item")[];
32+
export declare const MODES: {
33+
readonly JSON5: "json5";
34+
readonly JSON: "json4";
35+
readonly YAML: "yaml";
36+
};

cjs/constants.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.MODES =
4+
exports.COMPLEX_TYPES =
5+
exports.PRIMITIVE_TYPES =
6+
exports.JSON5_TOKENS_MAPPING =
7+
exports.YAML_TOKENS_MAPPING =
8+
exports.TOKENS =
9+
void 0;
10+
exports.TOKENS = {
11+
STRING: "String",
12+
NUMBER: "Number",
13+
TRUE: "True",
14+
FALSE: "False",
15+
NULL: "Null",
16+
OBJECT: "Object",
17+
ARRAY: "Array",
18+
PROPERTY: "Property",
19+
PROPERTY_NAME: "PropertyName",
20+
PROPERTY_COLON: "PropertyColon", // used in json5 grammar
21+
ITEM: "Item", // used in yaml grammar
22+
JSON_TEXT: "JsonText",
23+
INVALID: "⚠",
24+
};
25+
// TODO: To ensure that the YAML tokens are always mapped correctly,
26+
// we should change the TOKENS values to some other values and also create
27+
// mappings for the JSON tokens, which will force us to update all the token mappings whenever there is a change.
28+
exports.YAML_TOKENS_MAPPING = {
29+
Pair: exports.TOKENS.PROPERTY,
30+
Key: exports.TOKENS.PROPERTY_NAME,
31+
BlockSequence: exports.TOKENS.ARRAY,
32+
BlockMapping: exports.TOKENS.OBJECT,
33+
FlowSequence: exports.TOKENS.ARRAY,
34+
FlowMapping: exports.TOKENS.OBJECT,
35+
QuotedLiteral: exports.TOKENS.STRING,
36+
Literal: exports.TOKENS.STRING, // best guess
37+
Stream: exports.TOKENS.JSON_TEXT,
38+
Document: exports.TOKENS.OBJECT,
39+
};
40+
exports.JSON5_TOKENS_MAPPING = {
41+
File: exports.TOKENS.JSON_TEXT,
42+
};
43+
exports.PRIMITIVE_TYPES = [
44+
exports.TOKENS.STRING,
45+
exports.TOKENS.NUMBER,
46+
exports.TOKENS.TRUE,
47+
exports.TOKENS.FALSE,
48+
exports.TOKENS.NULL,
49+
];
50+
exports.COMPLEX_TYPES = [
51+
exports.TOKENS.OBJECT,
52+
exports.TOKENS.ARRAY,
53+
exports.TOKENS.ITEM,
54+
];
55+
exports.MODES = {
56+
JSON5: "json5",
57+
JSON: "json4",
58+
YAML: "yaml",
59+
};

cjs/features/completion.d.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { CompletionContext, CompletionResult } from "@codemirror/autocomplete";
2+
import { JSONMode } from "../types";
3+
import { DocumentParser } from "../parsers";
4+
export interface JSONCompletionOptions {
5+
mode?: JSONMode;
6+
jsonParser?: DocumentParser;
7+
}
8+
export declare class JSONCompletion {
9+
private opts;
10+
private originalSchema;
11+
/**
12+
* Inlined (expanded) top-level $ref if present.
13+
*/
14+
private schema;
15+
/**
16+
* Inlined (expanded) top-level $ref if present.
17+
* Does not contain any required properties and allows any additional properties everywhere.
18+
*/
19+
private laxSchema;
20+
private mode;
21+
private parser;
22+
constructor(opts: JSONCompletionOptions);
23+
doComplete(ctx: CompletionContext): never[] | CompletionResult;
24+
private doCompleteForSchema;
25+
private applySnippetCompletion;
26+
private getPropertyCompletions;
27+
private getInsertTextForProperty;
28+
private getInsertTextForPropertyName;
29+
private getInsertTextForString;
30+
private getInsertTextForGuessedValue;
31+
private getInsertTextForPlainText;
32+
private getInsertTextForValue;
33+
private getValueCompletions;
34+
private addSchemaValueCompletions;
35+
private addDefaultValueCompletions;
36+
private addEnumValueCompletions;
37+
private addBooleanValueCompletion;
38+
private addNullValueCompletion;
39+
private collectTypes;
40+
private getSchemas;
41+
private getAppliedValue;
42+
private getValueFromLabel;
43+
private extendedRegExp;
44+
}
45+
/**
46+
* provides a JSON schema enabled autocomplete extension for codemirror
47+
* @group Codemirror Extensions
48+
*/
49+
export declare function jsonCompletion(
50+
opts?: JSONCompletionOptions,
51+
): (ctx: CompletionContext) => never[] | CompletionResult;

0 commit comments

Comments
 (0)