Stream: t-compiler/rust-analyzer

Topic: <|> marker


kev (Jan 04 2021 at 15:28, on Zulip):

Hi,

I was wondering what the <|> marker means in tests?

An example that I saw of it was here:

         r"
            fn foo(x: String) {
                let x : &str = &x<|>;
            }",

loc: crates/hir_def/src/body/scope.rs [func: test_shadow_variable]

Jonas Schievink [he/him] (Jan 04 2021 at 15:30, on Zulip):

It places the cursor position

kev (Jan 04 2021 at 15:31, on Zulip):

Oh, why do you need to do that in tests?

Jonas Schievink [he/him] (Jan 04 2021 at 15:33, on Zulip):

because many of them test functionality that depends on the cursor position

Jonas Schievink [he/him] (Jan 04 2021 at 15:33, on Zulip):

like completions, goto def, etc.

Florian Diebold (Jan 04 2021 at 15:33, on Zulip):

in the end, it's just a way to specify a position in the text. what it actually means depends on the test

kev (Jan 04 2021 at 15:34, on Zulip):

I think the test I was looking at was for resolving definitions, in this case it is not needed at all, I'm guessing?

kev (Jan 04 2021 at 15:35, on Zulip):

But it needs to be specified by default?

Florian Diebold (Jan 04 2021 at 15:36, on Zulip):

no, if it wasn't needed it wouldn't be there. these tests check that the name at the cursor position resolves to a specific variable (given by specifying a position as a number; really it'd be nice to be able to specify two positions for these tests)

Florian Diebold (Jan 04 2021 at 15:37, on Zulip):
        let (db, position) = TestDB::with_position(ra_fixture);

you can just look at what the test function does with that position

kev (Jan 04 2021 at 15:40, on Zulip):

Florian Diebold said:

no, if it wasn't needed it wouldn't be there. these tests check that the name at the cursor position resolves to a specific variable (given by specifying a position as a number; really it'd be nice to be able to specify two positions for these tests)

This was also my initial thinking, then I saw also this test:

        do_check(
            r"
            fn quux(foo: i32) {
                let f = |bar, baz: i32| {
                    <|>
                };
            }",
            &["bar", "baz", "foo"],
        );

Where multiple variables are being resolved with only one marker

kev (Jan 04 2021 at 15:41, on Zulip):

Florian Diebold said:

        let (db, position) = TestDB::with_position(ra_fixture);

you can just look at what the test function does with that position

Alright will check this out now to see where I am misunderstanding

Laurențiu (Jan 04 2021 at 15:43, on Zulip):

kev said:

Where multiple variables are being resolved with only one marker

But the functionality tested there enumerates the variables visible in a lexical scope, so it's reasonable that a single cursor position will more than one variable.

matklad (Jan 04 2021 at 15:47, on Zulip):

btw, a long-standing task is to replace <|> with $0, to match snippets

kev (Jan 04 2021 at 15:51, on Zulip):

Laurențiu Nicola said:

kev said:

Where multiple variables are being resolved with only one marker

But the functionality tested there enumerates the variables visible in a lexical scope, so it's reasonable that a single cursor position will more than one variable.

That makes sense to me , parroting what Florian said earlier "in the end, it's just a way to specify a position in the text. what it actually means depends on the test"

So for resolution it is used to mark a position in the code, where lexically a set of variables should be visible

kev (Jan 04 2021 at 15:54, on Zulip):

matklad said:

btw, a long-standing task is to replace <|> with $0, to match snippets

I think this can be done by changing CURSOR_MARKER to $0 and then replace the usage of the old cursor marker in the code?

matklad (Jan 04 2021 at 16:00, on Zulip):

yup

kev (Jan 04 2021 at 16:12, on Zulip):

Oh alright, I thought that it would cause problems with tests that involve macros

kev (Jan 04 2021 at 16:12, on Zulip):

Is this also something that could be fixed?: https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/item_scope.rs#L231

kev (Jan 04 2021 at 16:13, on Zulip):

To me it seems that the if let may not be needed and you can do Some(fld) ?

Last update: Jul 26 2021 at 13:30UTC