Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope autocompletion problem #2

Open
yiffyrusdev opened this issue Oct 31, 2024 · 1 comment
Open

Scope autocompletion problem #2

yiffyrusdev opened this issue Oct 31, 2024 · 1 comment
Labels
keep-track This issue keeps track on something I don't know what to do about

Comments

@yiffyrusdev
Copy link
Owner

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.

@yiffyrusdev yiffyrusdev added the keep-track This issue keeps track on something I don't know what to do about label Oct 31, 2024
@yiffyrusdev
Copy link
Owner Author

I'm pretty happy with this commit.

Now we have to write styles in-quotes though:

styly!(scope:sass {"
    .sel
        color: red
"});

We don't benefit from unquoted style code anyway, because syntax highlighting is messy - sass isn't rust.

This way, The sass-tabbed-syntax indentation problem is also partially resolved.

And I get an opportunity to implement rust identifier injection, by reserving unqouted sass syntax for the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep-track This issue keeps track on something I don't know what to do about
Projects
None yet
Development

No branches or pull requests

1 participant