aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/release.yaml4
-rw-r--r--Cargo.lock64
-rw-r--r--crates/hir/src/code_model.rs12
-rw-r--r--crates/ssr/src/parsing.rs16
-rw-r--r--crates/ssr/src/tests.rs47
5 files changed, 81 insertions, 62 deletions
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index fd22ea88a..ece1fd364 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -146,7 +146,7 @@ jobs:
146 146
147 dist-aarch64-apple-darwin: 147 dist-aarch64-apple-darwin:
148 name: dist (aarch64-apple-darwin) 148 name: dist (aarch64-apple-darwin)
149 runs-on: macos-11.0 149 runs-on: macos-latest
150 env: 150 env:
151 RA_TARGET: aarch64-apple-darwin 151 RA_TARGET: aarch64-apple-darwin
152 152
@@ -163,7 +163,7 @@ jobs:
163 override: true 163 override: true
164 164
165 - name: Dist 165 - name: Dist
166 run: cargo xtask dist 166 run: SDKROOT=$(xcrun -sdk macosx11.0 --show-sdk-path) MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx11.0 --show-sdk-platform-version) cargo xtask dist
167 167
168 - name: Upload artifacts 168 - name: Upload artifacts
169 uses: actions/upload-artifact@v1 169 uses: actions/upload-artifact@v1
diff --git a/Cargo.lock b/Cargo.lock
index c625564dc..f87c590a4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -132,7 +132,7 @@ version = "0.12.0"
132source = "registry+https://github.com/rust-lang/crates.io-index" 132source = "registry+https://github.com/rust-lang/crates.io-index"
133checksum = "d5a5f7b42f606b7f23674f6f4d877628350682bc40687d3fae65679a58d55345" 133checksum = "d5a5f7b42f606b7f23674f6f4d877628350682bc40687d3fae65679a58d55345"
134dependencies = [ 134dependencies = [
135 "semver 0.11.0", 135 "semver",
136 "serde", 136 "serde",
137 "serde_json", 137 "serde_json",
138] 138]
@@ -488,19 +488,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
488checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" 488checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
489 489
490[[package]] 490[[package]]
491name = "generator"
492version = "0.6.23"
493source = "registry+https://github.com/rust-lang/crates.io-index"
494checksum = "8cdc09201b2e8ca1b19290cf7e65de2246b8e91fb6874279722189c4de7b94dc"
495dependencies = [
496 "cc",
497 "libc",
498 "log",
499 "rustc_version",
500 "winapi 0.3.9",
501]
502
503[[package]]
504name = "gimli" 491name = "gimli"
505version = "0.23.0" 492version = "0.23.0"
506source = "registry+https://github.com/rust-lang/crates.io-index" 493source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -834,19 +821,6 @@ dependencies = [
834] 821]
835 822
836[[package]] 823[[package]]
837name = "loom"
838version = "0.3.6"
839source = "registry+https://github.com/rust-lang/crates.io-index"
840checksum = "a0e8460f2f2121162705187214720353c517b97bdfb3494c0b1e33d83ebe4bed"
841dependencies = [
842 "cfg-if 0.1.10",
843 "generator",
844 "scoped-tls",
845 "serde",
846 "serde_json",
847]
848
849[[package]]
850name = "lsp-server" 824name = "lsp-server"
851version = "0.5.0" 825version = "0.5.0"
852source = "registry+https://github.com/rust-lang/crates.io-index" 826source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1414,15 +1388,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1414checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" 1388checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
1415 1389
1416[[package]] 1390[[package]]
1417name = "rustc_version"
1418version = "0.2.3"
1419source = "registry+https://github.com/rust-lang/crates.io-index"
1420checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
1421dependencies = [
1422 "semver 0.9.0",
1423]
1424
1425[[package]]
1426name = "ryu" 1391name = "ryu"
1427version = "1.0.5" 1392version = "1.0.5"
1428source = "registry+https://github.com/rust-lang/crates.io-index" 1393source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1480,31 +1445,16 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
1480 1445
1481[[package]] 1446[[package]]
1482name = "semver" 1447name = "semver"
1483version = "0.9.0"
1484source = "registry+https://github.com/rust-lang/crates.io-index"
1485checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
1486dependencies = [
1487 "semver-parser 0.7.0",
1488]
1489
1490[[package]]
1491name = "semver"
1492version = "0.11.0" 1448version = "0.11.0"
1493source = "registry+https://github.com/rust-lang/crates.io-index" 1449source = "registry+https://github.com/rust-lang/crates.io-index"
1494checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" 1450checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6"
1495dependencies = [ 1451dependencies = [
1496 "semver-parser 0.10.1", 1452 "semver-parser",
1497 "serde", 1453 "serde",
1498] 1454]
1499 1455
1500[[package]] 1456[[package]]
1501name = "semver-parser" 1457name = "semver-parser"
1502version = "0.7.0"
1503source = "registry+https://github.com/rust-lang/crates.io-index"
1504checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
1505
1506[[package]]
1507name = "semver-parser"
1508version = "0.10.1" 1458version = "0.10.1"
1509source = "registry+https://github.com/rust-lang/crates.io-index" 1459source = "registry+https://github.com/rust-lang/crates.io-index"
1510checksum = "42ef146c2ad5e5f4b037cd6ce2ebb775401729b19a82040c1beac9d36c7d1428" 1460checksum = "42ef146c2ad5e5f4b037cd6ce2ebb775401729b19a82040c1beac9d36c7d1428"
@@ -1566,12 +1516,11 @@ dependencies = [
1566 1516
1567[[package]] 1517[[package]]
1568name = "sharded-slab" 1518name = "sharded-slab"
1569version = "0.1.0" 1519version = "0.1.1"
1570source = "registry+https://github.com/rust-lang/crates.io-index" 1520source = "registry+https://github.com/rust-lang/crates.io-index"
1571checksum = "7b4921be914e16899a80adefb821f8ddb7974e3f1250223575a44ed994882127" 1521checksum = "79c719719ee05df97490f80a45acfc99e5a30ce98a1e4fb67aee422745ae14e3"
1572dependencies = [ 1522dependencies = [
1573 "lazy_static", 1523 "lazy_static",
1574 "loom",
1575] 1524]
1576 1525
1577[[package]] 1526[[package]]
@@ -1826,15 +1775,16 @@ dependencies = [
1826 1775
1827[[package]] 1776[[package]]
1828name = "tracing-tree" 1777name = "tracing-tree"
1829version = "0.1.6" 1778version = "0.1.7"
1830source = "registry+https://github.com/rust-lang/crates.io-index" 1779source = "registry+https://github.com/rust-lang/crates.io-index"
1831checksum = "43aac8afb493b08e1e1904956f7407c1e671b9c83b26a17e1bd83d6a3520e350" 1780checksum = "023e80cdb7c8468b7aade1d756afa2acbe2ae0a6142a25ec664b5239d6ef2794"
1832dependencies = [ 1781dependencies = [
1833 "ansi_term", 1782 "ansi_term",
1834 "atty", 1783 "atty",
1835 "chrono", 1784 "chrono",
1836 "termcolor", 1785 "termcolor",
1837 "tracing", 1786 "tracing",
1787 "tracing-log",
1838 "tracing-subscriber", 1788 "tracing-subscriber",
1839] 1789]
1840 1790
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index 071e553a8..1a4aa78fb 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -743,6 +743,18 @@ impl Function {
743 db.function_data(self.id).name.clone() 743 db.function_data(self.id).name.clone()
744 } 744 }
745 745
746 /// Get this function's return type
747 pub fn ret_type(self, db: &dyn HirDatabase) -> Type {
748 let resolver = self.id.resolver(db.upcast());
749 let ret_type = &db.function_data(self.id).ret_type;
750 let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
751 let environment = TraitEnvironment::lower(db, &resolver);
752 Type {
753 krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate,
754 ty: InEnvironment { value: Ty::from_hir_ext(&ctx, ret_type).0, environment },
755 }
756 }
757
746 pub fn self_param(self, db: &dyn HirDatabase) -> Option<SelfParam> { 758 pub fn self_param(self, db: &dyn HirDatabase) -> Option<SelfParam> {
747 if !db.function_data(self.id).has_self_param { 759 if !db.function_data(self.id).has_self_param {
748 return None; 760 return None;
diff --git a/crates/ssr/src/parsing.rs b/crates/ssr/src/parsing.rs
index 289affe90..3d5e4feb7 100644
--- a/crates/ssr/src/parsing.rs
+++ b/crates/ssr/src/parsing.rs
@@ -73,12 +73,18 @@ impl ParsedRule {
73 placeholders_by_stand_in: pattern.placeholders_by_stand_in(), 73 placeholders_by_stand_in: pattern.placeholders_by_stand_in(),
74 rules: Vec::new(), 74 rules: Vec::new(),
75 }; 75 };
76 builder.try_add(ast::Expr::parse(&raw_pattern), raw_template.map(ast::Expr::parse)); 76
77 let raw_template_stmt = raw_template.map(ast::Stmt::parse);
78 if let raw_template_expr @ Some(Ok(_)) = raw_template.map(ast::Expr::parse) {
79 builder.try_add(ast::Expr::parse(&raw_pattern), raw_template_expr);
80 } else {
81 builder.try_add(ast::Expr::parse(&raw_pattern), raw_template_stmt.clone());
82 }
77 builder.try_add(ast::Type::parse(&raw_pattern), raw_template.map(ast::Type::parse)); 83 builder.try_add(ast::Type::parse(&raw_pattern), raw_template.map(ast::Type::parse));
78 builder.try_add(ast::Item::parse(&raw_pattern), raw_template.map(ast::Item::parse)); 84 builder.try_add(ast::Item::parse(&raw_pattern), raw_template.map(ast::Item::parse));
79 builder.try_add(ast::Path::parse(&raw_pattern), raw_template.map(ast::Path::parse)); 85 builder.try_add(ast::Path::parse(&raw_pattern), raw_template.map(ast::Path::parse));
80 builder.try_add(ast::Pat::parse(&raw_pattern), raw_template.map(ast::Pat::parse)); 86 builder.try_add(ast::Pat::parse(&raw_pattern), raw_template.map(ast::Pat::parse));
81 builder.try_add(ast::Stmt::parse(&raw_pattern), raw_template.map(ast::Stmt::parse)); 87 builder.try_add(ast::Stmt::parse(&raw_pattern), raw_template_stmt);
82 builder.build() 88 builder.build()
83 } 89 }
84} 90}
@@ -89,7 +95,11 @@ struct RuleBuilder {
89} 95}
90 96
91impl RuleBuilder { 97impl RuleBuilder {
92 fn try_add<T: AstNode>(&mut self, pattern: Result<T, ()>, template: Option<Result<T, ()>>) { 98 fn try_add<T: AstNode, T2: AstNode>(
99 &mut self,
100 pattern: Result<T, ()>,
101 template: Option<Result<T2, ()>>,
102 ) {
93 match (pattern, template) { 103 match (pattern, template) {
94 (Ok(pattern), Some(Ok(template))) => self.rules.push(ParsedRule { 104 (Ok(pattern), Some(Ok(template))) => self.rules.push(ParsedRule {
95 placeholders_by_stand_in: self.placeholders_by_stand_in.clone(), 105 placeholders_by_stand_in: self.placeholders_by_stand_in.clone(),
diff --git a/crates/ssr/src/tests.rs b/crates/ssr/src/tests.rs
index c4149a849..db9cb8ca1 100644
--- a/crates/ssr/src/tests.rs
+++ b/crates/ssr/src/tests.rs
@@ -204,6 +204,53 @@ fn ssr_let_stmt_replace_expr() {
204} 204}
205 205
206#[test] 206#[test]
207fn ssr_blockexpr_replace_stmt_with_stmt() {
208 assert_ssr_transform(
209 "if $a() {$b;} ==>> $b;",
210 "{
211 if foo() {
212 bar();
213 }
214 Ok(())
215}",
216 expect![[r#"{
217 bar();
218 Ok(())
219}"#]],
220 );
221}
222
223#[test]
224fn ssr_blockexpr_match_trailing_expr() {
225 assert_matches(
226 "if $a() {$b;}",
227 "{
228 if foo() {
229 bar();
230 }
231}",
232 &["if foo() {
233 bar();
234 }"],
235 );
236}
237
238#[test]
239fn ssr_blockexpr_replace_trailing_expr_with_stmt() {
240 assert_ssr_transform(
241 "if $a() {$b;} ==>> $b;",
242 "{
243 if foo() {
244 bar();
245 }
246}",
247 expect![["{
248 bar();
249}"]],
250 );
251}
252
253#[test]
207fn ssr_function_to_method() { 254fn ssr_function_to_method() {
208 assert_ssr_transform( 255 assert_ssr_transform(
209 "my_function($a, $b) ==>> ($a).my_method($b)", 256 "my_function($a, $b) ==>> ($a).my_method($b)",