Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

trigger 'add annotation' code action everywhere between function name and body start

+62 -4
+5
compiler-core/src/analyse.rs
··· 498 498 publicity, 499 499 arguments, 500 500 body, 501 + body_start, 501 502 return_annotation, 502 503 end_position: end_location, 503 504 deprecation, ··· 714 715 publicity, 715 716 deprecation, 716 717 arguments: typed_arguments, 718 + body_start, 717 719 end_position: end_location, 718 720 return_annotation, 719 721 return_type: preregistered_type ··· 1439 1441 deprecation, 1440 1442 end_position: _, 1441 1443 body: _, 1444 + body_start: _, 1442 1445 return_type: _, 1443 1446 implementations, 1444 1447 purity, ··· 1798 1801 body, 1799 1802 return_annotation, 1800 1803 end_position: end_location, 1804 + body_start, 1801 1805 return_type, 1802 1806 external_erlang, 1803 1807 external_javascript, ··· 1858 1862 deprecation, 1859 1863 arguments, 1860 1864 end_position: end_location, 1865 + body_start, 1861 1866 return_annotation, 1862 1867 return_type, 1863 1868 body,
+1
compiler-core/src/ast.rs
··· 684 684 /// ``` 685 685 pub struct Function<T, Expr> { 686 686 pub location: SrcSpan, 687 + pub body_start: Option<u32>, 687 688 pub end_position: u32, 688 689 pub name: Option<SpannedString>, 689 690 pub arguments: Vec<Arg<T>>,
+1
compiler-core/src/call_graph/into_dependency_order_tests.rs
··· 33 33 .collect_vec(), 34 34 body: crate::parse::parse_statement_sequence(src).expect("syntax error"), 35 35 location: Default::default(), 36 + body_start: None, 36 37 return_annotation: None, 37 38 publicity: Publicity::Public, 38 39 deprecation: Deprecation::NotDeprecated,
+8 -1
compiler-core/src/language_server/code_action.rs
··· 1191 1191 fn visit_typed_function(&mut self, fun: &'ast ast::TypedFunction) { 1192 1192 ast::visit::visit_typed_function(self, fun); 1193 1193 1194 - let code_action_range = self.edits.src_span_to_lsp_range(fun.location); 1194 + let code_action_range = self.edits.src_span_to_lsp_range( 1195 + fun.body_start 1196 + .map(|body_start| SrcSpan { 1197 + start: fun.location.start, 1198 + end: body_start, 1199 + }) 1200 + .unwrap_or(fun.location), 1201 + ); 1195 1202 1196 1203 // Only offer the code action if the cursor is over the statement 1197 1204 if !overlaps(code_action_range, self.params.range) {
+18
compiler-core/src/language_server/tests/action.rs
··· 2951 2951 } 2952 2952 2953 2953 #[test] 2954 + fn add_annotation_triggers_on_function_curly_brace() { 2955 + assert_code_action!( 2956 + ADD_ANNOTATION, 2957 + "pub fn main() { 1 }", 2958 + find_position_of("{").to_selection(), 2959 + ); 2960 + } 2961 + 2962 + #[test] 2963 + fn add_annotation_triggers_on_empty_space_before_function_curly_brace() { 2964 + assert_code_action!( 2965 + ADD_ANNOTATION, 2966 + "pub fn main() { 1 }", 2967 + find_position_of(" ").nth_occurrence(3).to_selection(), 2968 + ); 2969 + } 2970 + 2971 + #[test] 2954 2972 fn adding_annotations_prints_contextual_types4() { 2955 2973 let src = r#" 2956 2974 import wibble as wobble
+11
compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__action__add_annotation_triggers_on_empty_space_before_function_curly_brace.snap
··· 1 + --- 2 + source: compiler-core/src/language_server/tests/action.rs 3 + expression: "pub fn main() { 1 }" 4 + --- 5 + ----- BEFORE ACTION 6 + pub fn main() { 1 } 7 + 8 + 9 + 10 + ----- AFTER ACTION 11 + pub fn main() -> Int { 1 }
+11
compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__action__add_annotation_triggers_on_function_curly_brace.snap
··· 1 + --- 2 + source: compiler-core/src/language_server/tests/action.rs 3 + expression: "pub fn main() { 1 }" 4 + --- 5 + ----- BEFORE ACTION 6 + pub fn main() { 1 } 7 + 8 + 9 + 10 + ----- AFTER ACTION 11 + pub fn main() -> Int { 1 }
+4 -3
compiler-core/src/parse.rs
··· 2049 2049 self.expect_one_following_series(&Token::RightParen, "a function parameter")?; 2050 2050 let return_annotation = self.parse_type_annotation(&Token::RArrow)?; 2051 2051 2052 - let (body, end, end_position) = match self.maybe_one(&Token::LeftBrace) { 2052 + let (body_start, body, end, end_position) = match self.maybe_one(&Token::LeftBrace) { 2053 2053 Some((left_brace_start, _)) => { 2054 2054 let some_body = self.parse_statement_seq()?; 2055 2055 let (_, right_brace_end) = self.expect_one(&Token::RightBrace)?; ··· 2071 2071 Some((body, _)) => body, 2072 2072 }; 2073 2073 2074 - (body, end, right_brace_end) 2074 + (Some(left_brace_start), body, end, right_brace_end) 2075 2075 } 2076 2076 2077 2077 None if is_anon => { ··· 2085 2085 let body = vec1![Statement::Expression(UntypedExpr::Placeholder { 2086 2086 location: SrcSpan::new(start, rpar_e) 2087 2087 })]; 2088 - (body, rpar_e, rpar_e) 2088 + (None, body, rpar_e, rpar_e) 2089 2089 } 2090 2090 }; 2091 2091 ··· 2093 2093 documentation, 2094 2094 location: SrcSpan { start, end }, 2095 2095 end_position, 2096 + body_start, 2096 2097 publicity: self.publicity(public, attributes.internal)?, 2097 2098 name, 2098 2099 arguments,
+3
compiler-core/src/parse/snapshots/gleam_core__parse__tests__record_access_no_label.snap
··· 87 87 start: 45, 88 88 end: 56, 89 89 }, 90 + body_start: Some( 91 + 57, 92 + ), 90 93 end_position: 75, 91 94 name: Some( 92 95 (