File tree Expand file tree Collapse file tree 2 files changed +50
-15
lines changed Expand file tree Collapse file tree 2 files changed +50
-15
lines changed Original file line number Diff line number Diff line change @@ -152,16 +152,26 @@ pub(crate) fn get_completions(
152
152
}
153
153
154
154
fn get_first_non_whitespace_in_source ( compilation : & Compilation , package_offset : u32 ) -> u32 {
155
+ const QSHARP_MAGIC : & str = "//qsharp" ;
155
156
let source = compilation
156
157
. user_unit ( )
157
158
. sources
158
159
. find_by_offset ( package_offset)
159
160
. expect ( "source should exist in the user source map" ) ;
160
161
161
- let first = source
162
- . contents
163
- . find ( |c : char | !c. is_whitespace ( ) )
164
- . unwrap_or ( source. contents . len ( ) ) ;
162
+ // Skip the //qsharp magic if it exists (notebook cells)
163
+ let start = if let Some ( qsharp_magic_start) = source. contents . find ( QSHARP_MAGIC ) {
164
+ qsharp_magic_start + QSHARP_MAGIC . len ( )
165
+ } else {
166
+ 0
167
+ } ;
168
+
169
+ let source_after_magic = & source. contents [ start..] ;
170
+
171
+ let first = start
172
+ + source_after_magic
173
+ . find ( |c : char | !c. is_whitespace ( ) )
174
+ . unwrap_or ( source_after_magic. len ( ) ) ;
165
175
166
176
let first = u32:: try_from ( first) . expect ( "source length should fit into u32" ) ;
167
177
Original file line number Diff line number Diff line change @@ -1038,8 +1038,20 @@ fn notebook_block() {
1038
1038
fn notebook_auto_open_start_of_cell_empty ( ) {
1039
1039
check_notebook (
1040
1040
& [
1041
- ( "cell1" , "namespace Foo { operation Bar() : Unit {} }" ) ,
1042
- ( "cell2" , "↘" ) ,
1041
+ (
1042
+ "cell1" ,
1043
+ indoc ! { "
1044
+ //qsharp
1045
+ namespace Foo { operation Bar() : Unit {} }"
1046
+ } ,
1047
+ ) ,
1048
+ (
1049
+ "cell2" ,
1050
+ indoc ! { "
1051
+ //qsharp
1052
+ ↘"
1053
+ } ,
1054
+ ) ,
1043
1055
] ,
1044
1056
& [ "Fake" ] ,
1045
1057
& expect ! [ [ r#"
@@ -1060,11 +1072,11 @@ fn notebook_auto_open_start_of_cell_empty() {
1060
1072
new_text: "open FakeStdLib;\n",
1061
1073
range: Range {
1062
1074
start: Position {
1063
- line: 0 ,
1075
+ line: 1 ,
1064
1076
column: 0,
1065
1077
},
1066
1078
end: Position {
1067
- line: 0 ,
1079
+ line: 1 ,
1068
1080
column: 0,
1069
1081
},
1070
1082
},
@@ -1082,8 +1094,21 @@ fn notebook_auto_open_start_of_cell_empty() {
1082
1094
fn notebook_auto_open_start_of_cell ( ) {
1083
1095
check_notebook (
1084
1096
& [
1085
- ( "cell1" , "namespace Foo { operation Bar() : Unit {} }" ) ,
1086
- ( "cell2" , r#" Message("hi") ↘"# ) ,
1097
+ (
1098
+ "cell1" ,
1099
+ indoc ! { "
1100
+ //qsharp
1101
+ namespace Foo { operation Bar() : Unit {} }"
1102
+ } ,
1103
+ ) ,
1104
+ (
1105
+ "cell2" ,
1106
+ indoc ! { r#"
1107
+ //qsharp
1108
+ Message("hi")
1109
+ ↘"#
1110
+ } ,
1111
+ ) ,
1087
1112
] ,
1088
1113
& [ "Fake" ] ,
1089
1114
& expect ! [ [ r#"
@@ -1101,15 +1126,15 @@ fn notebook_auto_open_start_of_cell() {
1101
1126
additional_text_edits: Some(
1102
1127
[
1103
1128
TextEdit {
1104
- new_text: "open FakeStdLib;\n ",
1129
+ new_text: "open FakeStdLib;\n",
1105
1130
range: Range {
1106
1131
start: Position {
1107
- line: 0 ,
1108
- column: 3 ,
1132
+ line: 1 ,
1133
+ column: 0 ,
1109
1134
},
1110
1135
end: Position {
1111
- line: 0 ,
1112
- column: 3 ,
1136
+ line: 1 ,
1137
+ column: 0 ,
1113
1138
},
1114
1139
},
1115
1140
},
You can’t perform that action at this time.
0 commit comments