File tree 4 files changed +42
-3
lines changed
4 files changed +42
-3
lines changed Original file line number Diff line number Diff line change 1
1
//! Scheduling, I/O, and API endpoints.
2
2
3
+ use std:: fmt;
4
+
3
5
use lsp_server as lsp;
4
6
use lsp_types as types;
5
7
use lsp_types:: InitializeParams ;
Original file line number Diff line number Diff line change @@ -48,7 +48,11 @@ impl super::BackgroundDocumentRequestHandler for CodeActions {
48
48
49
49
if snapshot. client_settings ( ) . fix_all ( ) {
50
50
if supported_code_actions. contains ( & SupportedCodeAction :: SourceFixAll ) {
51
- response. push ( fix_all ( & snapshot) . with_failure_code ( ErrorCode :: InternalError ) ?) ;
51
+ if snapshot. is_notebook_cell ( ) {
52
+ tracing:: debug!( "Ignoring `source.fixAll` code action for a notebook cell" ) ;
53
+ } else {
54
+ response. push ( fix_all ( & snapshot) . with_failure_code ( ErrorCode :: InternalError ) ?) ;
55
+ }
52
56
} else if supported_code_actions. contains ( & SupportedCodeAction :: NotebookSourceFixAll ) {
53
57
response
54
58
. push ( notebook_fix_all ( & snapshot) . with_failure_code ( ErrorCode :: InternalError ) ?) ;
@@ -57,8 +61,15 @@ impl super::BackgroundDocumentRequestHandler for CodeActions {
57
61
58
62
if snapshot. client_settings ( ) . organize_imports ( ) {
59
63
if supported_code_actions. contains ( & SupportedCodeAction :: SourceOrganizeImports ) {
60
- response
61
- . push ( organize_imports ( & snapshot) . with_failure_code ( ErrorCode :: InternalError ) ?) ;
64
+ if snapshot. is_notebook_cell ( ) {
65
+ tracing:: debug!(
66
+ "Ignoring `source.organizeImports` code action for a notebook cell"
67
+ ) ;
68
+ } else {
69
+ response. push (
70
+ organize_imports ( & snapshot) . with_failure_code ( ErrorCode :: InternalError ) ?,
71
+ ) ;
72
+ }
62
73
} else if supported_code_actions
63
74
. contains ( & SupportedCodeAction :: NotebookSourceOrganizeImports )
64
75
{
Original file line number Diff line number Diff line change @@ -50,6 +50,21 @@ impl super::BackgroundDocumentRequestHandler for CodeActionResolve {
50
50
. with_failure_code ( ErrorCode :: InvalidParams ) ;
51
51
} ;
52
52
53
+ match action_kind {
54
+ SupportedCodeAction :: SourceFixAll | SupportedCodeAction :: SourceOrganizeImports
55
+ if snapshot. is_notebook_cell ( ) =>
56
+ {
57
+ // This should never occur because we ignore generating these code actions for a
58
+ // notebook cell in the `textDocument/codeAction` request handler.
59
+ return Err ( anyhow:: anyhow!(
60
+ "Code action resolver cannot resolve {:?} for a notebook cell" ,
61
+ action_kind. to_kind( ) . as_str( )
62
+ ) )
63
+ . with_failure_code ( ErrorCode :: InvalidParams ) ;
64
+ }
65
+ _ => { }
66
+ }
67
+
53
68
action. edit = match action_kind {
54
69
SupportedCodeAction :: SourceFixAll | SupportedCodeAction :: NotebookSourceFixAll => Some (
55
70
resolve_edit_for_fix_all (
Original file line number Diff line number Diff line change @@ -184,4 +184,15 @@ impl DocumentSnapshot {
184
184
pub ( crate ) fn encoding ( & self ) -> PositionEncoding {
185
185
self . position_encoding
186
186
}
187
+
188
+ /// Returns `true` if this snapshot represents a notebook cell.
189
+ pub ( crate ) const fn is_notebook_cell ( & self ) -> bool {
190
+ matches ! (
191
+ & self . document_ref,
192
+ index:: DocumentQuery :: Notebook {
193
+ cell_url: Some ( _) ,
194
+ ..
195
+ }
196
+ )
197
+ }
187
198
}
You can’t perform that action at this time.
0 commit comments