Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 16, 2025. It is now read-only.

Commite2aa43e

Browse files
added yaml editor
1 parent9426ff3 commite2aa43e

File tree

4 files changed

+164
-0
lines changed

4 files changed

+164
-0
lines changed

‎docs/configure-coderabbit.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ sidebar_position: 3
1212
import SchemaViewer from "@site/src/components/SchemaViewer";
1313
```
1414

15+
```mdx-code-block
16+
import YamlEditor from "/src/components/YamlEditor/YamlEditor";
17+
```
18+
1519
CodeRabbit offers various configuration options to tailor the reviews to your
1620
requirements. Configuration can be made using one of the below options, in order
1721
of precedence:
@@ -56,6 +60,12 @@ chat:
5660
auto_reply:true
5761
```
5862
63+
Write your configuration file in the below editor to validate:
64+
65+
```mdx-code-block
66+
<YamlEditor />
67+
```
68+
5969
The configuration file can be used to set the following options:
6070

6171
```mdx-code-block

‎package-lock.json‎

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"postcss":"^8.4.32",
2828
"prism-react-renderer":"^2.3.0",
2929
"react":"^18.0.0",
30+
"react-ace":"^12.0.0",
3031
"react-dom":"^18.0.0",
3132
"tailwindcss":"^3.4.0"
3233
},
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import{React,useState}from"react";
2+
3+
importAceEditorfrom"react-ace";
4+
import"ace-builds/src-noconflict/theme-github";
5+
import"ace-builds/src-noconflict/ext-language_tools";
6+
7+
import"ace-builds/webpack-resolver";
8+
import"ace-builds/src-noconflict/mode-yaml";
9+
10+
importjsYamlfrom"js-yaml";
11+
12+
importAjvfrom"ajv";
13+
constajv=newAjv({allErrors:true});
14+
15+
importSchemafrom"../../../static/schema/schema.v2.json";
16+
17+
exportdefaultfunctionYamlEditor(){
18+
const[annotations,setAnnotations]=useState([]);
19+
const[value,setValue]=useState(
20+
"# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json\n"
21+
);
22+
constvalidate=ajv.compile(Schema.definitions.schema);
23+
functiongetRowFromPath(path){
24+
// Convert path to row number (0-based)
25+
returnpath.split("/").length-1;
26+
}
27+
functiongetLineNumber(yaml,path){
28+
constlines=yaml.split("\n");
29+
constpathParts=path.split("/").filter(Boolean);
30+
letcurrentObj=jsYaml.load(yaml);
31+
letlineNumber=0;
32+
33+
for(constpartofpathParts){
34+
for(leti=lineNumber;i<lines.length;i++){
35+
if(lines[i].trim().startsWith(part+":")){
36+
lineNumber=i;
37+
break;
38+
}
39+
}
40+
currentObj=currentObj[part];
41+
}
42+
43+
returnlineNumber;
44+
}
45+
functiononChange(newValue){
46+
setValue(newValue);
47+
try{
48+
constdoc=jsYaml.load(newValue,{strict:true});
49+
constvalid=validate(doc);
50+
console.log("Validation result:",valid);
51+
console.log("Validation errors:",validate.errors);
52+
53+
if(!valid&&validate.errors){
54+
setAnnotations(
55+
validate.errors.map((err)=>({
56+
row:err.instancePath
57+
?getLineNumber(newValue,err.instancePath)
58+
:0,
59+
column:0,
60+
text:`${err.keyword}:${err.message}${
61+
err?.params?.allowedValues
62+
?`Allowed values:${err.params.allowedValues.join(", ")}`
63+
:""
64+
}`,
65+
type:"error",
66+
}))
67+
);
68+
}else{
69+
setAnnotations([]);
70+
}
71+
}catch(err){
72+
console.error("Error:",err);
73+
console.log({
74+
errorMessage:err.reason,
75+
column:err.mark?.column,
76+
line:err.mark?.line,
77+
});
78+
setAnnotations([
79+
{
80+
row:err.instancePath ?getLineNumber(newValue,err.instancePath) :0,
81+
column:0,
82+
text:
83+
`${err.keyword}:${err.message}${
84+
err?.params?.allowedValues
85+
?`Allowed values:${err.params.allowedValues.join(", ")}`
86+
:""
87+
}`||"YAML parsing error",
88+
type:"error",
89+
},
90+
]);
91+
}
92+
}
93+
return(
94+
<AceEditor
95+
mode="yaml"
96+
theme="github"
97+
onChange={onChange}
98+
value={value}
99+
name="UNIQUE_ID_OF_DIV"
100+
editorProps={{$blockScrolling:true}}
101+
setOptions={{
102+
useWorker:false,
103+
showPrintMargin:false,
104+
showGutter:true,
105+
}}
106+
annotations={annotations}
107+
width="100%"
108+
height="400px"
109+
/>
110+
);
111+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp