Comments (9)
I'm a bit torn on this one. The way toml files are currently parsed is just a bunch of regexes. This works quite well actually, because we can make a lot of assumptions and be quite accommodating for invalid syntax like unclosed quotes or similar. The downside to it is that we can't realistically handle every syntactically correct way of specifying dependencies.
We could implement this additional case, but that would add complexity in many places. Maybe it is a common enough case though, that it would be worth supporting.
The "right" solution for this issue would be a lenient toml parser, that can handle any valid toml file you throw at it, and would combine the best of both worlds. A while ago I've dabbled a bit with writing one in rust, but that isn't far along, writing one in lua/teal, would be a bit of a pain and probably too slow to be a nice user experience.
Anyway, I'm currently quite busy and wouldn't have time to implement this myself.
from crates.nvim.
@Saecki doesn't Rust already have a TOML parser? I mean if cargo can parse them, then you could just borrow the code?
from crates.nvim.
Yes indeed, there are a lot of TOML parsers. Unfortunately most of them wont be able to recover from errors (they are not lenient). As a result we wouldn't be able to recover any information as soon as one syntax error occurs.
from crates.nvim.
Yes, but most of the time we are dealing with valid TOMLs? Would it be possible to use a parser & fall back to your current logic if the parser fails? Even when inserting versions or features, the state would be like this:
serde = ""
# or
serde = { version = "1.0", features = [] }
from crates.nvim.
I would argue the opposite, most of the time we are dealing with invalid TOMLs. When editing a file, most of the time the state is incomplete, and only stop when we archived the wanted result, which is a syntactically valid file. Especially when editing running two parsers at a time would probably mean double the latency, which is undesirable.
from crates.nvim.
Idk, in my experience, the TOML itself is usually valid. Operations such as removing crates/features or adding features or changing versions shouldn't break the TOML. It would probably only break if you start from an empty line. I usually copy an existing line & then modify it, so for me, the TOML is rarely broken.
Anyway, would it make sense to use parser + regex fallback if not in insert mode & using only regex if in insert mode? I think it would be a pretty nice tradeoff.
The biggest issue for me right now is that crates.nvim continues showing an error in NeoTree, even if I close the file. Many times, I open it just to check if crates are included or required features are enabled or not. There is no way to get rid of it without restarting nvim, which takes 10-15 seconds because I have a workspace with 50K+ lines & 800+ deps.
from crates.nvim.
Here is the minimum reproduction of the issue I'm facing btw:
==> Cargo.toml <==
[workspace]
members = ["crates1", "crates2"]
[dependencies]
crates1 = { version="0.1", path = "crates1" }
crates2 = { version="0.1", path = "crates2" }
==> crate1 <==
==> crate1/Cargo.toml <==
[package]
name = "crate1"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
==> crate1/src <==
==> crate1/src/lib.rs <==
pub fn add(left: usize, right: usize) -> usize {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
==> crate2 <==
==> crate2/Cargo.toml <==
[package]
name = "crate2"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
crate1 = { workspace=true, features = [] }
==> crate2/src <==
==> crate2/src/lib.rs <==
pub fn add(left: usize, right: usize) -> usize {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
In crate2/Cargo.toml
, I'm getting Error fetching crate
for crate1
. I'm assuming the issue is related to regex parsing too? If not, i can open a separate issue.
from crates.nvim.
I don't think this is related, could you move this to a separate issue?
from crates.nvim.
For anyone interested, I've been working on said parser lately.
from crates.nvim.
Related Issues (20)
- Better colored highlighting of updates in the plain text mode HOT 3
- EMFILE: too many open files HOT 3
- Error when using workspace crate with custom features HOT 9
- Figure out why CI is broken on PRs by contributors other than me
- autoupdate (throttle) exception. HOT 3
- Crate versions are lexicographically sorted in completion HOT 6
- `health#report_start` deprecation warning HOT 1
- feature: show version from workspace `Cargo.toml`
- False positive `Incorrect crate name casing` diagnostic
- Multiline arrays and features HOT 3
- null-ls is archived HOT 16
- nvim-cmp trigger needs some improvement HOT 6
- Mistake in readme HOT 1
- Toml LSP completion takes precendence over crates HOT 7
- `nvim-cmp` completions for crates don't show up HOT 6
- Breaking changes on main HOT 2
- Freezes neovim for several seconds HOT 2
- Ignoring invalid config key 'src.cmp' HOT 5
- cannot resume dead coroutine HOT 2
- Use lua type annotations instead of teal HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crates.nvim.