[gnome-builder] added formatter and possibility to trigger a full format from vim



commit bef094f855e672f545392b070996aa934ac62dcb
Author: Günther Wagner <info gunibert de>
Date:   Sun May 10 19:42:11 2020 +0200

    added formatter and possibility to trigger a full format from vim

 src/libide/lsp/ide-lsp-formatter.c                 |  2 +-
 src/plugins/rust-analyzer/meson.build              |  1 +
 .../rust-analyzer/rust-analyzer-formatter.c        | 59 ++++++++++++++++++++++
 .../rust-analyzer/rust-analyzer-formatter.h        | 31 ++++++++++++
 src/plugins/rust-analyzer/rust-analyzer.c          |  4 ++
 src/plugins/rust-analyzer/rust-analyzer.plugin     |  2 +-
 src/plugins/vim/keybindings/vim.css                |  1 +
 7 files changed, 98 insertions(+), 2 deletions(-)
---
diff --git a/src/libide/lsp/ide-lsp-formatter.c b/src/libide/lsp/ide-lsp-formatter.c
index 0a5c4c244..2f006c2dd 100644
--- a/src/libide/lsp/ide-lsp-formatter.c
+++ b/src/libide/lsp/ide-lsp-formatter.c
@@ -356,7 +356,7 @@ ide_lsp_formatter_format_range_async (IdeFormatter        *formatter,
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
 
   task = ide_task_new (self, cancellable, callback, user_data);
-  ide_task_set_source_tag (task, ide_lsp_formatter_format_async);
+  ide_task_set_source_tag (task, ide_lsp_formatter_format_range_async);
   ide_task_set_task_data (task, g_object_ref (buffer), g_object_unref);
 
   if (gtk_text_iter_compare (begin, end) > 0)
diff --git a/src/plugins/rust-analyzer/meson.build b/src/plugins/rust-analyzer/meson.build
index 7f7ce0f7e..492ed9844 100644
--- a/src/plugins/rust-analyzer/meson.build
+++ b/src/plugins/rust-analyzer/meson.build
@@ -6,6 +6,7 @@ plugins_sources += files([
   'rust-analyzer-completion-provider.c',
   'rust-analyzer-symbol-resolver.c',
   'rust-analyzer-diagnostic-provider.c',
+  'rust-analyzer-formatter.c',
   'rust-analyzer-transfer.c',
   'rust-analyzer-workbench-addin.c',
 ])
diff --git a/src/plugins/rust-analyzer/rust-analyzer-formatter.c 
b/src/plugins/rust-analyzer/rust-analyzer-formatter.c
new file mode 100644
index 000000000..8ddee6981
--- /dev/null
+++ b/src/plugins/rust-analyzer/rust-analyzer-formatter.c
@@ -0,0 +1,59 @@
+/* rust-analyzer-formatter.c
+ *
+ * Copyright 2020 Günther Wagner <info gunibert de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "rust-analyzer-formatter.h"
+#include "rust-analyzer-service.h"
+
+struct _RustAnalyzerFormatter
+{
+  IdeLspFormatter parent_instance;
+};
+
+static void provider_iface_init (IdeFormatterInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (RustAnalyzerFormatter,
+                         rust_analyzer_formatter,
+                         IDE_TYPE_LSP_FORMATTER,
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_FORMATTER, provider_iface_init))
+
+static void
+rust_analyzer_formatter_class_init (RustAnalyzerFormatterClass *klass)
+{
+}
+
+static void
+rust_analyzer_formatter_init (RustAnalyzerFormatter *self)
+{
+}
+
+static void
+rust_analyzer_formatter_load (IdeFormatter *self)
+{
+  IdeContext *context = ide_object_get_context (IDE_OBJECT (self));
+  RustAnalyzerService *service = ide_object_ensure_child_typed (IDE_OBJECT (context), 
RUST_TYPE_ANALYZER_SERVICE);
+  g_object_bind_property (service, "client", self, "client", G_BINDING_SYNC_CREATE);
+  rust_analyzer_service_ensure_started (service);
+}
+
+static void
+provider_iface_init (IdeFormatterInterface *iface)
+{
+  iface->load = rust_analyzer_formatter_load;
+}
diff --git a/src/plugins/rust-analyzer/rust-analyzer-formatter.h 
b/src/plugins/rust-analyzer/rust-analyzer-formatter.h
new file mode 100644
index 000000000..cd1640631
--- /dev/null
+++ b/src/plugins/rust-analyzer/rust-analyzer-formatter.h
@@ -0,0 +1,31 @@
+/* rust-analyzer-formatter.h
+ *
+ * Copyright 2020 Günther Wagner <info gunibert de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-lsp.h>
+
+G_BEGIN_DECLS
+
+#define RUST_TYPE_ANALYZER_FORMATTER (rust_analyzer_formatter_get_type())
+
+G_DECLARE_FINAL_TYPE (RustAnalyzerFormatter, rust_analyzer_formatter, RUST, ANALYZER_FORMATTER, 
IdeLspFormatter)
+
+G_END_DECLS
diff --git a/src/plugins/rust-analyzer/rust-analyzer.c b/src/plugins/rust-analyzer/rust-analyzer.c
index c9b38d35f..6fbbfc10b 100644
--- a/src/plugins/rust-analyzer/rust-analyzer.c
+++ b/src/plugins/rust-analyzer/rust-analyzer.c
@@ -24,6 +24,7 @@
 #include "rust-analyzer-completion-provider.h"
 #include "rust-analyzer-symbol-resolver.h"
 #include "rust-analyzer-diagnostic-provider.h"
+#include "rust-analyzer-formatter.h"
 #include "rust-analyzer-workbench-addin.h"
 
 _IDE_EXTERN void
@@ -41,4 +42,7 @@ _rust_analyzer_register_types (PeasObjectModule *module)
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_DIAGNOSTIC_PROVIDER,
                                               RUST_TYPE_ANALYZER_DIAGNOSTIC_PROVIDER);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_FORMATTER,
+                                              RUST_TYPE_ANALYZER_FORMATTER);
 }
diff --git a/src/plugins/rust-analyzer/rust-analyzer.plugin b/src/plugins/rust-analyzer/rust-analyzer.plugin
index 9ec32a765..5a1ee9326 100644
--- a/src/plugins/rust-analyzer/rust-analyzer.plugin
+++ b/src/plugins/rust-analyzer/rust-analyzer.plugin
@@ -9,7 +9,7 @@ Name=Rust Analyzer Language Server Integration
 X-Completion-Provider-Languages=rust
 X-Diagnostic-Provider-Languages=rust
 X-Symbol-Resolver-Languages=rust
-#X-Formatter-Languages=rust
+X-Formatter-Languages=rust
 #X-Highlighter-Languages=rust
 #X-Hover-Provider-Languages=rust
 #X-Rename-Provider-Languages=rust
diff --git a/src/plugins/vim/keybindings/vim.css b/src/plugins/vim/keybindings/vim.css
index 134f6cf38..2914d913f 100644
--- a/src/plugins/vim/keybindings/vim.css
+++ b/src/plugins/vim/keybindings/vim.css
@@ -1725,6 +1725,7 @@
   /* cycle "tabs" */
   bind "<shift>t" { "action" ("frame", "previous-page", "") };
   bind "t" { "action" ("frame", "next-page", "") };
+  bind "q" { "format-selection" () };
 }
 
 @binding-set builder-vim-source-view-normal-g-u


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]