Commit bef094f8 authored by Günther Wagner's avatar Günther Wagner Committed by Christian Hergert

added formatter and possibility to trigger a full format from vim

parent 1d11a736
......@@ -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)
......
......@@ -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',
])
......
/* 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;
}
/* 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
......@@ -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);
}
......@@ -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
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment