summaryrefslogtreecommitdiff
path: root/tests/integration/lsp_tests.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2024-09-02 18:27:25 +0100
committerGitHub <noreply@github.com>2024-09-02 18:27:25 +0100
commite804175a0ad850f09086b70368042ac50cee116e (patch)
treef4f4f89d9c9dceef9244363224ca5deacd293a60 /tests/integration/lsp_tests.rs
parent9e6f41df664036ca723c2657e11234258e5a6fcb (diff)
feat(lsp): html/css/yaml file formatting (#25353)
Diffstat (limited to 'tests/integration/lsp_tests.rs')
-rw-r--r--tests/integration/lsp_tests.rs139
1 files changed, 139 insertions, 0 deletions
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs
index f6dee785d..7c7e9315c 100644
--- a/tests/integration/lsp_tests.rs
+++ b/tests/integration/lsp_tests.rs
@@ -10592,6 +10592,145 @@ fn lsp_format_markdown() {
}
#[test]
+fn lsp_format_html() {
+ let context = TestContextBuilder::new().use_temp_cwd().build();
+ let temp_dir = context.temp_dir();
+ temp_dir.write(
+ "deno.json",
+ json!({
+ "unstable": ["fmt-html"],
+ })
+ .to_string(),
+ );
+ let html_file =
+ source_file(temp_dir.path().join("file.html"), " <html></html>");
+ let mut client = context.new_lsp_command().build();
+ client.initialize_default();
+ let res = client.write_request(
+ "textDocument/formatting",
+ json!({
+ "textDocument": { "uri": html_file.url() },
+ "options": {
+ "tabSize": 2,
+ "insertSpaces": true,
+ },
+ }),
+ );
+ assert_eq!(
+ res,
+ json!([
+ {
+ "range": {
+ "start": { "line": 0, "character": 0 },
+ "end": { "line": 0, "character": 2 },
+ },
+ "newText": "",
+ },
+ {
+ "range": {
+ "start": { "line": 0, "character": 15 },
+ "end": { "line": 0, "character": 15 },
+ },
+ "newText": "\n",
+ },
+ ]),
+ );
+ client.shutdown();
+}
+
+#[test]
+fn lsp_format_css() {
+ let context = TestContextBuilder::new().use_temp_cwd().build();
+ let temp_dir = context.temp_dir();
+ temp_dir.write(
+ "deno.json",
+ json!({
+ "unstable": ["fmt-css"],
+ })
+ .to_string(),
+ );
+ let css_file = source_file(temp_dir.path().join("file.css"), " foo {}");
+ let mut client = context.new_lsp_command().build();
+ client.initialize_default();
+ let res = client.write_request(
+ "textDocument/formatting",
+ json!({
+ "textDocument": { "uri": css_file.url() },
+ "options": {
+ "tabSize": 2,
+ "insertSpaces": true,
+ },
+ }),
+ );
+ assert_eq!(
+ res,
+ json!([
+ {
+ "range": {
+ "start": { "line": 0, "character": 0 },
+ "end": { "line": 0, "character": 2 },
+ },
+ "newText": "",
+ },
+ {
+ "range": {
+ "start": { "line": 0, "character": 8 },
+ "end": { "line": 0, "character": 8 },
+ },
+ "newText": "\n",
+ },
+ ]),
+ );
+ client.shutdown();
+}
+
+#[test]
+fn lsp_format_yaml() {
+ let context = TestContextBuilder::new().use_temp_cwd().build();
+ let temp_dir = context.temp_dir();
+ temp_dir.write(
+ "deno.json",
+ json!({
+ "unstable": ["fmt-yaml"],
+ })
+ .to_string(),
+ );
+ let yaml_file = source_file(temp_dir.path().join("file.yaml"), " foo: 1");
+ let mut client = context.new_lsp_command().build();
+ client.initialize_default();
+ let res = client.write_request(
+ "textDocument/formatting",
+ json!({
+ "textDocument": { "uri": yaml_file.url() },
+ "options": {
+ "tabSize": 2,
+ "insertSpaces": true,
+ },
+ }),
+ );
+ assert_eq!(
+ res,
+ json!([
+ {
+ "range": {
+ "start": { "line": 0, "character": 0 },
+ "end": { "line": 0, "character": 2 },
+ },
+ "newText": "",
+ },
+ {
+ "range": {
+ "start": { "line": 0, "character": 8 },
+ "end": { "line": 0, "character": 8 },
+ },
+ "newText": "\n",
+ },
+ ]),
+ );
+ client.shutdown();
+}
+
+#[test]
fn lsp_format_with_config() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let temp_dir = context.temp_dir();