Skip to content

Commit

Permalink
Merge #2513
Browse files Browse the repository at this point in the history
2513: ⬆️ nightly IDEA & rust r=Undin a=Undin



Co-authored-by: Arseniy Pendryak <a.pendryak@yandex.ru>
  • Loading branch information
bors[bot] and Undin committed Jun 25, 2018
2 parents d912b05 + 757dee0 commit 376e51a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -10,7 +10,7 @@ jdk: oraclejdk8

env:
matrix:
- RUST_VERSION=nightly-2018-04-15 ORG_GRADLE_PROJECT_sinceBuild=181 ORG_GRADLE_PROJECT_ideaVersion=181.4668.14 # modified by script
- RUST_VERSION=nightly-2018-06-24 ORG_GRADLE_PROJECT_sinceBuild=181 ORG_GRADLE_PROJECT_ideaVersion=181.5281.18 # modified by script
- RUST_VERSION=1.25.0 ORG_GRADLE_PROJECT_sinceBuild=181 ORG_GRADLE_PROJECT_ideaVersion=2018.1

install: true
Expand Down
15 changes: 12 additions & 3 deletions src/main/kotlin/org/rust/ide/template/postfix/utils.kt
Expand Up @@ -17,6 +17,7 @@ import org.rust.lang.core.psi.ext.ancestors
import org.rust.lang.core.types.type
import org.rust.lang.core.types.ty.TyBool
import org.rust.lang.utils.negate
import org.rust.openapiext.isUnitTestMode

internal object RsPostfixTemplatePsiInfo : PostfixTemplatePsiInfo() {
override fun getNegatedExpression(element: PsiElement): PsiElement =
Expand All @@ -29,11 +30,19 @@ internal object RsPostfixTemplatePsiInfo : PostfixTemplatePsiInfo() {
abstract class RsExprParentsSelectorBase(val pred: (RsExpr) -> Boolean) : PostfixTemplateExpressionSelector {
override fun getRenderer(): Function<PsiElement, String> = Function { it.text }

abstract override fun getExpressions(context: PsiElement, document: Document, offset: Int): List<PsiElement>
final override fun getExpressions(context: PsiElement, document: Document, offset: Int): List<PsiElement> {
val expressions = getExpressionsInternal(context, document, offset)
// `PostfixTemplateWithExpressionSelector#expand` selects only one item from this list in unit tests.
// But in different platform versions different items are selected (of course, it's very convenient).
// So let's return the latest item to commit tests behavior with all platform versions
return if (isUnitTestMode) listOfNotNull(expressions.lastOrNull()) else expressions
}

protected abstract fun getExpressionsInternal(context: PsiElement, document: Document, offset: Int): List<PsiElement>
}

class RsTopMostInScopeSelector(pred: ((RsExpr) -> Boolean) = { true }) : RsExprParentsSelectorBase(pred) {
override fun getExpressions(context: PsiElement, document: Document, offset: Int): List<PsiElement> =
override fun getExpressionsInternal(context: PsiElement, document: Document, offset: Int): List<PsiElement> =
context
.ancestors
.takeWhile { it !is RsBlock && it.textRange.endOffset == context.textRange.endOffset }
Expand All @@ -48,7 +57,7 @@ class RsTopMostInScopeSelector(pred: ((RsExpr) -> Boolean) = { true }) : RsExprP
}

class RsAllParentsSelector(pred: ((RsExpr) -> Boolean) = { true }) : RsExprParentsSelectorBase(pred) {
override fun getExpressions(context: PsiElement, document: Document, offset: Int): List<PsiElement> =
override fun getExpressionsInternal(context: PsiElement, document: Document, offset: Int): List<PsiElement> =
context
.ancestors
.takeWhile { it !is RsBlock }
Expand Down
7 changes: 4 additions & 3 deletions src/test/kotlin/org/rust/ide/docs/RsExternalDocUrlStdTest.kt
Expand Up @@ -66,12 +66,13 @@ class RsExternalDocUrlStdTest : RsDocumentationProviderTest() {
}
""", "https://doc.rust-lang.org/alloc/vec/struct.Vec.html#method.new")

// FIXME: it should generate `https://doc.rust-lang.org/std/primitive.pointer.html#method.is_null`
fun `test primitive method`() = doUrlTestByText("""
fn main() {
let x = 0.0f64.is_nan();
fn foo(ptr: *const i32) {
let x = ptr.is_null();
//^
}
""", "https://doc.rust-lang.org/std/primitive.f64.html#method.is_nan")
""", "https://doc.rust-lang.org/core/primitive.pointer.html#method.is_null")

fun `test tymethod`() = doUrlTestByText("""
fn foo<T: Default>() -> T {
Expand Down
18 changes: 12 additions & 6 deletions src/test/kotlin/org/rust/lang/core/resolve/RsStdlibResolveTest.kt
Expand Up @@ -114,19 +114,21 @@ class RsStdlibResolveTest : RsResolveTestBase() {
//^ unresolved
""")

// BACKCOMPAT: Rust 1.26.0
fun `test string slice resolve`() = stubOnlyResolve("""
//- main.rs
fn main() { "test".lines(); }
//^ ...str.rs
//^ ...str.rs|...str/mod.rs
""")

// BACKCOMPAT: Rust 1.26.0
fun `test slice resolve`() = stubOnlyResolve("""
//- main.rs
fn main() {
let x : [i32];
x.iter()
//^ ...slice.rs
//^ ...slice.rs|...slice/mod.rs
}
""")

Expand Down Expand Up @@ -277,10 +279,13 @@ class RsStdlibResolveTest : RsResolveTestBase() {

fun `test array indexing`() = stubOnlyResolve("""
//- main.rs
struct Foo(i32);
impl Foo { fn foo(&self) {} }
fn main() {
let xs = ["foo", "bar"];
xs[0].len();
//^ ...str.rs
let xs = [Foo(0), Foo(123)];
xs[0].foo();
//^ ...main.rs
}
""")

Expand All @@ -292,11 +297,12 @@ class RsStdlibResolveTest : RsResolveTestBase() {
}
""")

// BACKCOMPAT: Rust 1.26.0
fun `test vec slice`() = stubOnlyResolve("""
//- main.rs
fn foo(xs: Vec<i32>) {
xs[0..3].len();
//^ ...slice.rs
//^ ...slice.rs|...slice/mod.rs
}
""")

Expand Down

0 comments on commit 376e51a

Please sign in to comment.