Skip to content

Commit f3c1871

Browse files
committed
Modernize VSCode extension and fix formatting issues
1 parent 348208d commit f3c1871

24 files changed

Lines changed: 6637 additions & 6977 deletions

.vscode/launch.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Run extension",
6+
"type": "extensionHost",
7+
"request": "launch",
8+
"args": ["--extensionDevelopmentPath=${workspaceFolder}/packages/extension"],
9+
"outFiles": ["${workspaceFolder}/packages/extension/dist/*.js"],
10+
"preLaunchTask": "Build extension"
11+
}
12+
]
13+
}

.vscode/settings.json

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
{
22
"editor.formatOnSave": true,
3+
"js/ts.tsc.autoDetect": "off",
34
"[toml]": {
45
"editor.formatOnSave": false
56
},
67
"[handlebars]": {
78
"editor.formatOnSave": false
89
},
10+
"editor.rulers": [100],
11+
"[json]": {
12+
"editor.formatOnSave": false,
13+
"editor.defaultFormatter": "esbenp.prettier-vscode"
14+
},
15+
"[jsonc]": {
16+
"editor.formatOnSave": false,
17+
"editor.defaultFormatter": "esbenp.prettier-vscode"
18+
},
919
"[javascript]": {
10-
"editor.formatOnSave": false
20+
"editor.formatOnSave": false,
21+
"editor.defaultFormatter": "esbenp.prettier-vscode"
22+
},
23+
"[typescript]": {
24+
"editor.formatOnSave": false,
25+
"editor.defaultFormatter": "esbenp.prettier-vscode"
1126
},
1227
"[html]": {
13-
"editor.formatOnSave": false
28+
"editor.formatOnSave": false,
29+
"editor.defaultFormatter": "esbenp.prettier-vscode"
1430
},
1531
"dioxus.formatOnSave": "disabled",
1632
// "rust-analyzer.check.workspace": true,
@@ -21,7 +37,5 @@
2137
// "rust-analyzer.check.allTargets": true,
2238
"rust-analyzer.cargo.features": "all",
2339
"rust-analyzer.check.features": "all",
24-
"rust-analyzer.cargo.extraArgs": [
25-
"--tests"
26-
],
27-
}
40+
"rust-analyzer.cargo.extraArgs": ["--tests"]
41+
}

.vscode/tasks.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "Build extension",
6+
"options": { "cwd": "packages/extension" },
7+
"type": "npm",
8+
"script": "build:debug",
9+
"problemMatcher": ["$rustc", "$tsc"]
10+
}
11+
]
12+
}

Cargo.lock

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

packages/autofmt/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ syn = { workspace = true, features = [
2121
] }
2222
serde = { workspace = true, features = ["derive"] }
2323
prettyplease = { workspace = true }
24+
tracing = { workspace = true }
2425
regex = "1.11.1"
2526

2627
[dev-dependencies]

packages/autofmt/src/prettier_please.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub fn unparse_expr(expr: &Expr, src: &str, cfg: &IndentOptions) -> String {
9191
replacer.visit_expr_mut(&mut modified_expr);
9292

9393
// now unparsed with the modified expression
94-
let mut unparsed = unparse_inner(&modified_expr);
94+
let mut unparsed = unparse_inner(&modified_expr, cfg);
9595

9696
// now we can replace the macros with the formatted blocks
9797
for fmted in replacer.formatted_stack.drain(..) {
@@ -105,11 +105,11 @@ pub fn unparse_expr(expr: &Expr, src: &str, cfg: &IndentOptions) -> String {
105105
out_fmt.push(' ');
106106
}
107107

108-
let mut whitespace = 0;
108+
let mut indent_level = 0;
109109

110110
for line in unparsed.lines() {
111111
if line.contains(MARKER) {
112-
whitespace = line.matches(cfg.indent_str()).count();
112+
indent_level = line.matches(cfg.indent_str()).count();
113113
break;
114114
}
115115
}
@@ -119,7 +119,7 @@ pub fn unparse_expr(expr: &Expr, src: &str, cfg: &IndentOptions) -> String {
119119
while let Some((_idx, fmt_line)) = lines.next() {
120120
// Push the indentation (but not for blank lines - avoid trailing whitespace)
121121
if is_multiline && !fmt_line.is_empty() {
122-
out_fmt.push_str(&cfg.indent_str().repeat(whitespace));
122+
out_fmt.push_str(&cfg.indent_str().repeat(indent_level));
123123
}
124124

125125
// Calculate delta between indentations - the block indentation is too much
@@ -133,7 +133,7 @@ pub fn unparse_expr(expr: &Expr, src: &str, cfg: &IndentOptions) -> String {
133133

134134
if is_multiline {
135135
out_fmt.push('\n');
136-
out_fmt.push_str(&cfg.indent_str().repeat(whitespace));
136+
out_fmt.push_str(&cfg.indent_str().repeat(indent_level));
137137
} else if !is_empty {
138138
out_fmt.push(' ');
139139
}
@@ -161,10 +161,10 @@ pub fn unparse_expr(expr: &Expr, src: &str, cfg: &IndentOptions) -> String {
161161
///
162162
/// This creates a new temporary file, parses the expression into it, and then formats the file.
163163
/// This is a bit of a hack, but dtonlay doesn't want to support this very simple usecase, forcing us to clone the expr
164-
pub fn unparse_inner(expr: &Expr) -> String {
164+
pub fn unparse_inner(expr: &Expr, cfg: &IndentOptions) -> String {
165165
let file = wrapped(expr);
166166
let wrapped = prettyplease::unparse(&file);
167-
unwrapped(wrapped)
167+
unwrapped(wrapped, cfg)
168168
}
169169

170170
/// Unparse a pattern into a properly formatted string using prettyplease.
@@ -194,14 +194,27 @@ pub fn unparse_pat(pat: &syn::Pat) -> String {
194194
}
195195

196196
// Split off the fn main and then cut the tabs off the front
197-
fn unwrapped(raw: String) -> String {
197+
fn unwrapped(raw: String, cfg: &IndentOptions) -> String {
198+
const INDENT: &str = " ";
199+
198200
let mut o = raw
199201
.strip_prefix("fn main() {\n")
200202
.unwrap()
201203
.strip_suffix("}\n")
202204
.unwrap()
203205
.lines()
204-
.map(|line| line.strip_prefix(" ").unwrap_or_default()) // todo: set this to tab level
206+
.map(|line| line.strip_prefix(INDENT).unwrap_or(line))
207+
.map(|mut line| {
208+
let indent_level = line.matches(INDENT).count();
209+
210+
for _ in 0..indent_level {
211+
if let Some(remaining) = line.strip_prefix(INDENT) {
212+
line = remaining;
213+
}
214+
}
215+
216+
cfg.indent_str().repeat(indent_level) + line
217+
})
205218
.collect::<Vec<_>>()
206219
.join("\n");
207220

packages/extension/.eslintrc.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/extension/.gitignore

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
.DS_Store
2-
npm-debug.log
3-
Thumbs.db
4-
*/node_modules/
5-
node_modules/
6-
*/out/
7-
out/
8-
*/.vs/
9-
.vs/
10-
tsconfig.lsif.json
11-
*.lsif
12-
*.db
1+
# Dependencies
2+
node_modules
3+
4+
# Build artifacts
5+
dist
6+
pkg
137
*.vsix
14-
pkg/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"MD013": { "line_length": 100 },
3+
"MD033": false
4+
}

packages/extension/.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"trailingComma": "all",
5+
"printWidth": 100,
6+
"arrowParens": "avoid"
7+
}

0 commit comments

Comments
 (0)