Skip to content

Scope autocompletion problem #2

Description

@yiffyrusdev

Posting this just to keep track on that annoying issue

The problem

Currently, using the "sass-in-rust" styling, like the following:

styly!(scope {
    .sel1.sel2 {}
});

One can't get proper scope:: autocompletion from rust-analyzer.

It seems to work with styly!(scope "path/to/file.scss") though.

The root of evil

While I was writing the parsing part of procmacro, I've noticed then styly! seems to receive nothing where brackets with the code should be, just like if I wrote bare styly!(scope );

Initially, the code which parses arbitrary style in brackets was:

// sabry_procmacro_impl/src/impls/mod.rs
// impl Parse for ArbitraryStyleBlock
// fn parse

let _s;
braced!(_s in input);
let stream = _s.parse::<TokenStream>()?;
let c = match stream.span().source_text() {
    Some(stx) => stx,
    // TODO: rust-analyzer does fall into this even if all is fine
    None => return Err(syn::Error::new(stream.span(), "Source code expected")),
};

And that was the cause of editor false-positive error "Source code expected".

Now it looks like this:

let _s;
braced!(_s in input);
let stream = _s.parse::<TokenStream>()?;

let c = match stream.span().source_text() {
    Some(stx) => stx,
    // TODO: rust-analyzer does fall into this even if all is fine
    None => "".to_string(), //return Err(syn::Error::new(stream.span(), "Source code expected")),
};

So i've just decided to treat None-ish tokenstream's source_text as empty sourcecode.

I'm completely unsure if that's the proper way to extract source code from the ParseBuffer.

I'm aware of the fact that we could just do the input.to_string() within the proc-macro itself, however that's not the case for sabry, as we do the scoping before CSS compilation and parsing the string again and again is a bad idea.

What to do next

It's very annoying not to have autocompletion for selectors, because the selector identifier in rusty scope doesn't always match the selector identifier in style code.

So I need to investigate -- why does it even happen with rust-analyzer, and why does it work as expected with rustc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    keep-trackThis issue keeps track on something I don't know what to do about

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions