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.

Commite0a6698

Browse files
added yaml editor (#74)
* added yaml editor* name fix* moved component to one code block* removed logs
1 parent9426ff3 commite0a6698

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

‎docs/configure-coderabbit.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ sidebar_position: 3
1010

1111
```mdx-code-block
1212
import SchemaViewer from "@site/src/components/SchemaViewer";
13+
import YamlEditor from "/src/components/YamlEditor/YamlEditor";
1314
```
1415

1516
CodeRabbit offers various configuration options to tailor the reviews to your
@@ -56,6 +57,12 @@ chat:
5657
auto_reply:true
5758
```
5859
60+
Write your configuration file in the below editor to validate:
61+
62+
```mdx-code-block
63+
<YamlEditor />
64+
```
65+
5966
The configuration file can be used to set the following options:
6067

6168
```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: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
51+
if(!valid&&validate.errors){
52+
setAnnotations(
53+
validate.errors.map((err)=>({
54+
row:err.instancePath
55+
?getLineNumber(newValue,err.instancePath)
56+
:0,
57+
column:0,
58+
text:`${err.keyword}:${err.message}${
59+
err?.params?.allowedValues
60+
?`Allowed values:${err.params.allowedValues.join(", ")}`
61+
:""
62+
}`,
63+
type:"error",
64+
}))
65+
);
66+
}else{
67+
setAnnotations([]);
68+
}
69+
}catch(err){
70+
setAnnotations([
71+
{
72+
row:err.instancePath ?getLineNumber(newValue,err.instancePath) :0,
73+
column:0,
74+
text:
75+
`${err.keyword}:${err.message}${
76+
err?.params?.allowedValues
77+
?`Allowed values:${err.params.allowedValues.join(", ")}`
78+
:""
79+
}`||"YAML parsing error",
80+
type:"error",
81+
},
82+
]);
83+
}
84+
}
85+
return(
86+
<AceEditor
87+
mode="yaml"
88+
theme="github"
89+
onChange={onChange}
90+
value={value}
91+
name="yaml-editor"
92+
editorProps={{$blockScrolling:true}}
93+
setOptions={{
94+
useWorker:false,
95+
showPrintMargin:false,
96+
showGutter:true,
97+
}}
98+
annotations={annotations}
99+
width="100%"
100+
height="400px"
101+
/>
102+
);
103+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp