Skip to content

Commit

Permalink
feat(utils): add support for 1.2 in code completions
Browse files Browse the repository at this point in the history
  • Loading branch information
ttrzeng authored and Talent Zeng committed Aug 22, 2024
1 parent bdc2f3c commit 35647a9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/constants/schema-version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum SchemaVersion {
OneDotZero = "1.0",
OneDotOne = "1.1",
OneDotTwo = "1.2",
}
18 changes: 18 additions & 0 deletions src/tools/monaco/providers/code-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ const errorFixesByErrorCodeAndSchema: Partial<
text: `${SINGLE_INDENTATION}${SINGLE_INDENTATION}${Keyword.DEFINE} ${relation}: [typeName]\n${lineContent}`,
};
},
[SchemaVersion.OneDotTwo]: ({ model, marker, relation }) => {
const lineContent = model.getLineContent(marker.startLineNumber);
return {
startColumn: 0,
title: `Fix: add definition for \`${relation}\`.`,
text: `${SINGLE_INDENTATION}${SINGLE_INDENTATION}${Keyword.DEFINE} ${relation}: [typeName]\n${lineContent}`,
};
},
},
[errors.ValidationError.SelfError]: {
[SchemaVersion.OneDotZero]: ({ text }) => ({
Expand All @@ -58,6 +66,10 @@ const errorFixesByErrorCodeAndSchema: Partial<
title: `Fix: replace \`${text}\` with type restrictions.`,
text: "[typeName]",
}),
[SchemaVersion.OneDotTwo]: ({ text }) => ({
title: `Fix: replace \`${text}\` with type restrictions.`,
text: "[typeName]",
}),
},
[errors.ValidationError.DuplicatedError]: {
[SchemaVersion.OneDotZero]: ({ model, marker, markerRange, text }) => ({
Expand All @@ -72,6 +84,12 @@ const errorFixesByErrorCodeAndSchema: Partial<
title: `Fix: remove duplicated \`${text}\`.`,
text: "",
}),
[SchemaVersion.OneDotTwo]: ({ model, marker, markerRange, text }) => ({
startLineNumber: markerRange.startLineNumber - 1,
startColumn: model.getLineContent(marker.startLineNumber - 1).length + 1,
title: `Fix: remove duplicated \`${text}\`.`,
text: "",
}),
},
};

Expand Down
3 changes: 2 additions & 1 deletion src/tools/monaco/providers/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function getSuggestions(
label: `sample-${key}`,
kind: monaco.languages.CompletionItemKind.Struct,
insertText: transformer.transformJSONToDSL(
schemaVersion === SchemaVersion.OneDotOne
schemaVersion === SchemaVersion.OneDotOne || schemaVersion === SchemaVersion.OneDotTwo
? sampleModel
: {
schema_version: SchemaVersion.OneDotZero,
Expand Down Expand Up @@ -228,6 +228,7 @@ export const provideCompletionItems =
) =>
(model: editor.ITextModel, position: Position): languages.ProviderResult<languages.CompletionList> => {
switch (schemaVersion) {
case SchemaVersion.OneDotTwo:
case SchemaVersion.OneDotOne:
return provideCompletionItemsOneDotOne(monaco, completionExtraOptions)(model, position);
case SchemaVersion.OneDotZero:
Expand Down

0 comments on commit 35647a9

Please sign in to comment.