Skip to content

Commit 09539bb

Browse files
Merge branch 'refactor/json' into feat/wasm-try-2
2 parents c83a0ec + d11bc7a commit 09539bb

File tree

3 files changed

+116
-4
lines changed

3 files changed

+116
-4
lines changed

crates/pglt_workspace/src/configuration.rs

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub fn create_config(
169169
}
170170
})?;
171171

172-
// we now check if biome is installed inside `node_modules` and if so, we use the schema from there
172+
// we now check if pglt is installed inside `node_modules` and if so, we use the schema from there
173173
if VERSION == "0.0.0" {
174174
let schema_path = Path::new("./node_modules/@pglt/pglt/schema.json");
175175
let options = OpenOptions::default().read(true);
@@ -265,3 +265,110 @@ pub fn strip_jsonc_comments(jsonc_input: &str) -> String {
265265

266266
json_output
267267
}
268+
269+
#[cfg(test)]
270+
mod tests {
271+
use super::*;
272+
273+
#[test]
274+
fn test_strip_jsonc_comments_line_comments() {
275+
let input = r#"{
276+
"name": "test", // This is a line comment
277+
"value": 42 // Another comment
278+
}"#;
279+
280+
let expected = r#"{
281+
"name": "test",
282+
"value": 42
283+
}
284+
"#;
285+
286+
assert_eq!(strip_jsonc_comments(input), expected);
287+
}
288+
289+
#[test]
290+
fn test_strip_jsonc_comments_block_comments() {
291+
let input = r#"{
292+
/* This is a block comment */
293+
"name": "test",
294+
"value": /* inline comment */ 42
295+
}"#;
296+
297+
let expected = r#"{
298+
299+
"name": "test",
300+
"value": 42
301+
}
302+
"#;
303+
304+
assert_eq!(strip_jsonc_comments(input), expected);
305+
}
306+
307+
#[test]
308+
fn test_strip_jsonc_comments_nested_block_comments() {
309+
let input = r#"{
310+
/* Outer comment /* Nested comment */ still outer */
311+
"name": "test"
312+
}"#;
313+
314+
let expected = r#"{
315+
316+
"name": "test"
317+
}
318+
"#;
319+
320+
assert_eq!(strip_jsonc_comments(input), expected);
321+
}
322+
323+
#[test]
324+
fn test_strip_jsonc_comments_in_strings() {
325+
let input = r#"{
326+
"comment_like": "This is not a // comment",
327+
"another": "This is not a /* block comment */ either"
328+
}"#;
329+
330+
let expected = r#"{
331+
"comment_like": "This is not a // comment",
332+
"another": "This is not a /* block comment */ either"
333+
}
334+
"#;
335+
336+
assert_eq!(strip_jsonc_comments(input), expected);
337+
}
338+
339+
#[test]
340+
fn test_strip_jsonc_comments_escaped_quotes() {
341+
let input = r#"{
342+
"escaped\": \"quote": "value", // Comment after escaped quotes
343+
"normal": "value" // Normal comment
344+
}"#;
345+
346+
let expected = r#"{
347+
"escaped\": \"quote": "value",
348+
"normal": "value"
349+
}
350+
"#;
351+
352+
assert_eq!(strip_jsonc_comments(input), expected);
353+
}
354+
355+
#[test]
356+
fn test_strip_jsonc_comments_multiline_block() {
357+
let input = r#"{
358+
/* This is a
359+
multiline block
360+
comment */
361+
"name": "test"
362+
}"#;
363+
364+
let expected = r#"{
365+
366+
367+
368+
"name": "test"
369+
}
370+
"#;
371+
372+
assert_eq!(strip_jsonc_comments(input), expected);
373+
}
374+
}

docs/codegen/src/utils.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ pub(crate) fn replace_section(
1212
section_identifier, section_identifier
1313
);
1414
let re = Regex::new(&pattern).unwrap();
15-
re.replace_all(content, format!("${{1}}{}${{2}}", replacement))
16-
.to_string()
15+
16+
// Use a replacement function instead of a replacement string to avoid
17+
// issues with special characters like $ in the replacement text
18+
re.replace_all(content, |caps: &regex::Captures| {
19+
format!("{}{}{}", &caps[1], replacement, &caps[2])
20+
})
21+
.to_string()
1722
}
1823

1924
#[derive(Default)]

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ After running the `init` command, you’ll have a `pglt.jsonc` file in your dire
4141

4242
```json
4343
{
44-
"": "https://supabase-community.github.io/postgres_lsp/schemas/0.0.0/schema.json",
44+
"$schema": "https://supabase-community.github.io/postgres_lsp/schemas/0.0.0/schema.json",
4545
"vcs": {
4646
"enabled": false,
4747
"clientKind": "git",

0 commit comments

Comments
 (0)