Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Günther Wagner
gnome-builder
Commits
fc97a0ab
Commit
fc97a0ab
authored
May 12, 2020
by
Günther Wagner
Browse files
rust-analyzer: guards and contracts for functions
parent
b29abab8
Pipeline
#178553
passed with stage
in 36 minutes and 59 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/plugins/rust-analyzer/rust-analyzer-completion-provider.c
View file @
fc97a0ab
...
...
@@ -47,7 +47,12 @@ static void
rust_analyzer_completion_provider_load
(
IdeCompletionProvider
*
self
,
IdeContext
*
context
)
{
RustAnalyzerService
*
service
=
ide_object_ensure_child_typed
(
IDE_OBJECT
(
context
),
RUST_TYPE_ANALYZER_SERVICE
);
RustAnalyzerService
*
service
=
NULL
;
g_return_if_fail
(
RUST_IS_ANALYZER_COMPLETION_PROVIDER
(
self
));
g_return_if_fail
(
IDE_IS_CONTEXT
(
context
));
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
);
}
...
...
src/plugins/rust-analyzer/rust-analyzer-diagnostic-provider.c
View file @
fc97a0ab
...
...
@@ -46,8 +46,13 @@ rust_analyzer_diagnostic_provider_init (RustAnalyzerDiagnosticProvider *self)
static
void
rust_analyzer_diagnostic_provider_load
(
IdeDiagnosticProvider
*
self
)
{
IdeContext
*
context
=
ide_object_get_context
(
IDE_OBJECT
(
self
));
RustAnalyzerService
*
service
=
ide_object_ensure_child_typed
(
IDE_OBJECT
(
context
),
RUST_TYPE_ANALYZER_SERVICE
);
RustAnalyzerService
*
service
=
NULL
;
IdeContext
*
context
=
NULL
;
g_return_if_fail
(
RUST_IS_ANALYZER_DIAGNOSTIC_PROVIDER
(
self
));
context
=
ide_object_get_context
(
IDE_OBJECT
(
self
));
service
=
ide_object_ensure_child_typed
(
IDE_OBJECT
(
context
),
RUST_TYPE_ANALYZER_SERVICE
);
rust_analyzer_service_ensure_started
(
service
);
g_object_bind_property
(
service
,
"client"
,
self
,
"client"
,
G_BINDING_SYNC_CREATE
);
}
...
...
src/plugins/rust-analyzer/rust-analyzer-formatter.c
View file @
fc97a0ab
...
...
@@ -46,8 +46,13 @@ 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
);
IdeContext
*
context
=
NULL
;
RustAnalyzerService
*
service
=
NULL
;
g_return_if_fail
(
RUST_IS_ANALYZER_FORMATTER
(
self
));
context
=
ide_object_get_context
(
IDE_OBJECT
(
self
));
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
);
}
...
...
src/plugins/rust-analyzer/rust-analyzer-service.c
View file @
fc97a0ab
...
...
@@ -63,6 +63,8 @@ _cargo_toml_changed_cb (GFileMonitor *monitor,
{
RustAnalyzerService
*
self
=
RUST_ANALYZER_SERVICE
(
user_data
);
g_return_if_fail
(
RUST_IS_ANALYZER_SERVICE
(
self
));
if
(
self
->
supervisor
!=
NULL
)
{
IdeSubprocess
*
subprocess
=
ide_subprocess_supervisor_get_subprocess
(
self
->
supervisor
);
...
...
@@ -231,6 +233,8 @@ _handle_notification (IdeLspClient *client,
const
gchar
*
token
=
NULL
;
const
gchar
*
kind
=
NULL
;
g_return_if_fail
(
IDE_IS_LSP_CLIENT
(
client
));
if
(
!
ide_str_equal0
(
method
,
"$/progress"
))
return
;
...
...
@@ -272,12 +276,15 @@ rust_analyzer_service_lsp_started (IdeSubprocessSupervisor *supervisor,
IdeSubprocess
*
subprocess
,
gpointer
user_data
)
{
RustAnalyzerService
*
self
=
RUST_ANALYZER_SERVICE
(
user_data
);
g_autoptr
(
GIOStream
)
io_stream
=
NULL
;
GInputStream
*
input
;
GOutputStream
*
output
;
IdeLspClient
*
client
=
NULL
;
RustAnalyzerService
*
self
=
RUST_ANALYZER_SERVICE
(
user_data
);
g_return_if_fail
(
RUST_IS_ANALYZER_SERVICE
(
self
));
g_return_if_fail
(
IDE_IS_SUBPROCESS_SUPERVISOR
(
supervisor
));
g_return_if_fail
(
IDE_IS_SUBPROCESS
(
subprocess
));
input
=
ide_subprocess_get_stdout_pipe
(
subprocess
);
output
=
ide_subprocess_get_stdin_pipe
(
subprocess
);
...
...
@@ -300,12 +307,14 @@ rust_analyzer_service_lsp_started (IdeSubprocessSupervisor *supervisor,
static
gboolean
rust_analyzer_service_check_rust_analyzer_bin
(
RustAnalyzerService
*
self
)
{
/
/
Check if `rust-analyzer` can be found on PATH or if there is an executable
//
in typical location
/
*
Check if `rust-analyzer` can be found on PATH or if there is an executable
in typical location
*/
g_autoptr
(
GFile
)
rust_analyzer_bin_file
=
NULL
;
g_autofree
gchar
*
rust_analyzer_bin
=
NULL
;
g_autoptr
(
GFileInfo
)
file_info
=
NULL
;
g_return_val_if_fail
(
RUST_IS_ANALYZER_SERVICE
(
self
),
FALSE
);
rust_analyzer_bin
=
g_find_program_in_path
(
"rust-analyzer"
);
if
(
rust_analyzer_bin
==
NULL
)
{
...
...
@@ -339,6 +348,8 @@ rust_analyzer_service_check_rust_analyzer_bin (RustAnalyzerService *self)
void
rust_analyzer_service_ensure_started
(
RustAnalyzerService
*
self
)
{
g_return_if_fail
(
RUST_IS_ANALYZER_SERVICE
(
self
));
if
(
self
->
state
==
RUST_ANALYZER_SERVICE_INIT
)
{
if
(
!
rust_analyzer_service_check_rust_analyzer_bin
(
self
))
...
...
src/plugins/rust-analyzer/rust-analyzer-symbol-resolver.c
View file @
fc97a0ab
...
...
@@ -46,8 +46,13 @@ rust_analyzer_symbol_resolver_init (RustAnalyzerSymbolResolver *self)
static
void
rust_analyzer_symbol_resolver_load
(
IdeSymbolResolver
*
self
)
{
IdeContext
*
context
=
ide_object_get_context
(
IDE_OBJECT
(
self
));
RustAnalyzerService
*
service
=
ide_object_ensure_child_typed
(
IDE_OBJECT
(
context
),
RUST_TYPE_ANALYZER_SERVICE
);
IdeContext
*
context
=
NULL
;
RustAnalyzerService
*
service
=
NULL
;
g_return_if_fail
(
RUST_IS_ANALYZER_SYMBOL_RESOLVER
(
self
));
context
=
ide_object_get_context
(
IDE_OBJECT
(
self
));
service
=
ide_object_ensure_child_typed
(
IDE_OBJECT
(
context
),
RUST_TYPE_ANALYZER_SERVICE
);
rust_analyzer_service_ensure_started
(
service
);
g_object_bind_property
(
service
,
"client"
,
self
,
"client"
,
G_BINDING_SYNC_CREATE
);
}
...
...
src/plugins/rust-analyzer/rust-analyzer-transfer.c
View file @
fc97a0ab
...
...
@@ -54,10 +54,12 @@ _downloaded_chunk (GObject *source_object,
GAsyncResult
*
result
,
gpointer
user_data
)
{
g_autofree
gchar
*
statusmsg
=
NULL
;
g_autoptr
(
GError
)
error
=
NULL
;
GInputStream
*
stream
=
G_INPUT_STREAM
(
source_object
);
DownloadData
*
data
=
user_data
;
g_autofree
gchar
*
statusmsg
=
NULL
;
g_autoptr
(
GError
)
error
=
NULL
;
g_return_if_fail
(
G_IS_INPUT_STREAM
(
stream
));
gsize
count
=
g_input_stream_read_finish
(
stream
,
result
,
&
error
);
if
(
error
!=
NULL
)
...
...
@@ -98,12 +100,15 @@ _download_lsp (GObject *source_object,
gpointer
user_data
)
{
g_autoptr
(
IdeTask
)
task
=
IDE_TASK
(
user_data
);
SoupRequest
*
request
=
SOUP_REQUEST
(
source_object
);
g_autoptr
(
GFile
)
file
=
NULL
;
g_autoptr
(
GError
)
error
=
NULL
;
SoupRequest
*
request
=
SOUP_REQUEST
(
source_object
);
GInputStream
*
stream
=
NULL
;
DownloadData
*
data
;
g_return_if_fail
(
SOUP_IS_REQUEST
(
request
));
g_return_if_fail
(
IDE_IS_TASK
(
task
));
stream
=
soup_request_send_finish
(
request
,
result
,
NULL
);
data
=
g_slice_new0
(
DownloadData
);
...
...
@@ -134,6 +139,7 @@ rust_analyzer_transfer_execute_async (IdeTransfer *transfer,
g_autoptr
(
SoupRequest
)
request
=
NULL
;
g_autoptr
(
GError
)
error
=
NULL
;
g_return_if_fail
(
RUST_IS_ANALYZER_TRANSFER
(
self
));
g_assert
(
!
cancellable
||
G_IS_CANCELLABLE
(
cancellable
));
task
=
ide_task_new
(
self
,
cancellable
,
callback
,
user_data
);
...
...
src/plugins/rust-analyzer/rust-analyzer-workbench-addin.c
View file @
fc97a0ab
...
...
@@ -61,8 +61,8 @@ rust_analyzer_service_downloaded_lsp (GObject *object,
GAsyncResult
*
res
,
gpointer
user_data
)
{
RustAnalyzerService
*
service
=
NULL
;
IdeContext
*
context
=
IDE_CONTEXT
(
user_data
);
RustAnalyzerService
*
service
=
NULL
;
g_return_if_fail
(
IDE_IS_CONTEXT
(
context
));
...
...
@@ -78,6 +78,8 @@ rust_analyzer_workbench_addin_remove_lsp (IdeTransfer *transfer,
g_autofree
gchar
*
rust_analyzer_path
=
NULL
;
g_autoptr
(
GFile
)
rust_analyzer_bin
=
NULL
;
g_return_if_fail
(
IDE_IS_TRANSFER
(
transfer
));
rust_analyzer_path
=
g_build_filename
(
g_get_home_dir
(),
".cargo"
,
"bin"
,
"rust-analyzer"
,
NULL
);
rust_analyzer_bin
=
g_file_new_for_path
(
rust_analyzer_path
);
g_file_trash
(
rust_analyzer_bin
,
NULL
,
NULL
);
...
...
@@ -88,12 +90,14 @@ rust_analyzer_workbench_addin_install_rust_analyzer (GSimpleAction *action,
GVariant
*
parameter
,
gpointer
user_data
)
{
IdeContext
*
context
=
IDE_CONTEXT
(
user_data
);
g_autoptr
(
RustAnalyzerTransfer
)
transfer
=
NULL
;
IdeNotifications
*
notifications
=
NULL
;
IdeNotification
*
notification
=
NULL
;
IdeTransferManager
*
transfer_manager
=
NULL
;
IdeContext
*
context
=
IDE_CONTEXT
(
user_data
);
g_return_if_fail
(
G_IS_SIMPLE_ACTION
(
action
));
g_return_if_fail
(
IDE_IS_CONTEXT
(
context
));
notifications
=
ide_object_get_child_typed
(
IDE_OBJECT
(
context
),
IDE_TYPE_NOTIFICATIONS
);
notification
=
ide_notifications_find_by_id
(
notifications
,
"org.gnome-builder.rust-analyzer"
);
...
...
@@ -121,6 +125,9 @@ rust_analyzer_workbench_addin_workspace_added (IdeWorkbenchAddin *addin,
{
GSimpleAction
*
install_rust_analyzer
=
NULL
;
g_return_if_fail
(
RUST_IS_ANALYZER_WORKBENCH_ADDIN
(
addin
));
g_return_if_fail
(
IDE_IS_WORKSPACE
(
workspace
));
install_rust_analyzer
=
g_simple_action_new
(
"install-rust-analyzer"
,
NULL
);
g_simple_action_set_enabled
(
install_rust_analyzer
,
TRUE
);
g_signal_connect
(
install_rust_analyzer
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment