mirror of
https://github.com/denoland/deno.git
synced 2025-01-08 15:19:40 -05:00
fix(lsp): css preprocessor formatting (#27526)
This commit is contained in:
parent
7d66018874
commit
79c0b2ce73
3 changed files with 88 additions and 5 deletions
|
@ -64,6 +64,9 @@ pub enum LanguageId {
|
||||||
Markdown,
|
Markdown,
|
||||||
Html,
|
Html,
|
||||||
Css,
|
Css,
|
||||||
|
Scss,
|
||||||
|
Sass,
|
||||||
|
Less,
|
||||||
Yaml,
|
Yaml,
|
||||||
Sql,
|
Sql,
|
||||||
Svelte,
|
Svelte,
|
||||||
|
@ -86,6 +89,9 @@ impl LanguageId {
|
||||||
LanguageId::Markdown => Some("md"),
|
LanguageId::Markdown => Some("md"),
|
||||||
LanguageId::Html => Some("html"),
|
LanguageId::Html => Some("html"),
|
||||||
LanguageId::Css => Some("css"),
|
LanguageId::Css => Some("css"),
|
||||||
|
LanguageId::Scss => Some("scss"),
|
||||||
|
LanguageId::Sass => Some("sass"),
|
||||||
|
LanguageId::Less => Some("less"),
|
||||||
LanguageId::Yaml => Some("yaml"),
|
LanguageId::Yaml => Some("yaml"),
|
||||||
LanguageId::Sql => Some("sql"),
|
LanguageId::Sql => Some("sql"),
|
||||||
LanguageId::Svelte => Some("svelte"),
|
LanguageId::Svelte => Some("svelte"),
|
||||||
|
@ -107,6 +113,9 @@ impl LanguageId {
|
||||||
LanguageId::Markdown => Some("text/markdown"),
|
LanguageId::Markdown => Some("text/markdown"),
|
||||||
LanguageId::Html => Some("text/html"),
|
LanguageId::Html => Some("text/html"),
|
||||||
LanguageId::Css => Some("text/css"),
|
LanguageId::Css => Some("text/css"),
|
||||||
|
LanguageId::Scss => None,
|
||||||
|
LanguageId::Sass => None,
|
||||||
|
LanguageId::Less => None,
|
||||||
LanguageId::Yaml => Some("application/yaml"),
|
LanguageId::Yaml => Some("application/yaml"),
|
||||||
LanguageId::Sql => None,
|
LanguageId::Sql => None,
|
||||||
LanguageId::Svelte => None,
|
LanguageId::Svelte => None,
|
||||||
|
@ -140,6 +149,9 @@ impl FromStr for LanguageId {
|
||||||
"markdown" => Ok(Self::Markdown),
|
"markdown" => Ok(Self::Markdown),
|
||||||
"html" => Ok(Self::Html),
|
"html" => Ok(Self::Html),
|
||||||
"css" => Ok(Self::Css),
|
"css" => Ok(Self::Css),
|
||||||
|
"scss" => Ok(Self::Scss),
|
||||||
|
"sass" => Ok(Self::Sass),
|
||||||
|
"less" => Ok(Self::Less),
|
||||||
"yaml" => Ok(Self::Yaml),
|
"yaml" => Ok(Self::Yaml),
|
||||||
"sql" => Ok(Self::Sql),
|
"sql" => Ok(Self::Sql),
|
||||||
"svelte" => Ok(Self::Svelte),
|
"svelte" => Ok(Self::Svelte),
|
||||||
|
|
|
@ -11889,13 +11889,22 @@ fn lsp_format_html() {
|
||||||
fn lsp_format_css() {
|
fn lsp_format_css() {
|
||||||
let context = TestContextBuilder::new().use_temp_cwd().build();
|
let context = TestContextBuilder::new().use_temp_cwd().build();
|
||||||
let temp_dir = context.temp_dir();
|
let temp_dir = context.temp_dir();
|
||||||
let file = source_file(temp_dir.path().join("file.css"), " foo {}");
|
let css_file = source_file(temp_dir.path().join("file.css"), " foo {}\n");
|
||||||
|
let scss_file = source_file(temp_dir.path().join("file.scss"), " $font-stack: Helvetica, sans-serif;\n\nbody {\n font: 100% $font-stack;\n}\n");
|
||||||
|
let sass_file = source_file(
|
||||||
|
temp_dir.path().join("file.sass"),
|
||||||
|
" $font-stack: Helvetica, sans-serif\n\nbody\n font: 100% $font-stack\n",
|
||||||
|
);
|
||||||
|
let less_file = source_file(
|
||||||
|
temp_dir.path().join("file.less"),
|
||||||
|
" @width: 10px;\n\n#header {\n width: @width;\n}\n",
|
||||||
|
);
|
||||||
let mut client = context.new_lsp_command().build();
|
let mut client = context.new_lsp_command().build();
|
||||||
client.initialize_default();
|
client.initialize_default();
|
||||||
let res = client.write_request(
|
let res = client.write_request(
|
||||||
"textDocument/formatting",
|
"textDocument/formatting",
|
||||||
json!({
|
json!({
|
||||||
"textDocument": { "uri": file.url() },
|
"textDocument": { "uri": css_file.url() },
|
||||||
"options": {
|
"options": {
|
||||||
"tabSize": 2,
|
"tabSize": 2,
|
||||||
"insertSpaces": true,
|
"insertSpaces": true,
|
||||||
|
@ -11912,12 +11921,71 @@ fn lsp_format_css() {
|
||||||
},
|
},
|
||||||
"newText": "",
|
"newText": "",
|
||||||
},
|
},
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
let res = client.write_request(
|
||||||
|
"textDocument/formatting",
|
||||||
|
json!({
|
||||||
|
"textDocument": { "uri": scss_file.url() },
|
||||||
|
"options": {
|
||||||
|
"tabSize": 2,
|
||||||
|
"insertSpaces": true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
res,
|
||||||
|
json!([
|
||||||
{
|
{
|
||||||
"range": {
|
"range": {
|
||||||
"start": { "line": 0, "character": 8 },
|
"start": { "line": 0, "character": 0 },
|
||||||
"end": { "line": 0, "character": 8 },
|
"end": { "line": 0, "character": 2 },
|
||||||
},
|
},
|
||||||
"newText": "\n",
|
"newText": "",
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
let res = client.write_request(
|
||||||
|
"textDocument/formatting",
|
||||||
|
json!({
|
||||||
|
"textDocument": { "uri": sass_file.url() },
|
||||||
|
"options": {
|
||||||
|
"tabSize": 2,
|
||||||
|
"insertSpaces": true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
res,
|
||||||
|
json!([
|
||||||
|
{
|
||||||
|
"range": {
|
||||||
|
"start": { "line": 0, "character": 0 },
|
||||||
|
"end": { "line": 0, "character": 2 },
|
||||||
|
},
|
||||||
|
"newText": "",
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
let res = client.write_request(
|
||||||
|
"textDocument/formatting",
|
||||||
|
json!({
|
||||||
|
"textDocument": { "uri": less_file.url() },
|
||||||
|
"options": {
|
||||||
|
"tabSize": 2,
|
||||||
|
"insertSpaces": true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
res,
|
||||||
|
json!([
|
||||||
|
{
|
||||||
|
"range": {
|
||||||
|
"start": { "line": 0, "character": 0 },
|
||||||
|
"end": { "line": 0, "character": 2 },
|
||||||
|
},
|
||||||
|
"newText": "",
|
||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
|
@ -1289,6 +1289,9 @@ impl SourceFile {
|
||||||
"md" => "markdown",
|
"md" => "markdown",
|
||||||
"html" => "html",
|
"html" => "html",
|
||||||
"css" => "css",
|
"css" => "css",
|
||||||
|
"scss" => "scss",
|
||||||
|
"sass" => "sass",
|
||||||
|
"less" => "less",
|
||||||
"yaml" => "yaml",
|
"yaml" => "yaml",
|
||||||
"sql" => "sql",
|
"sql" => "sql",
|
||||||
"svelte" => "svelte",
|
"svelte" => "svelte",
|
||||||
|
|
Loading…
Reference in a new issue