Skip to content

FileLines::all().to_json_spans() returns [] which is parsed as empty map #3649

Closed
@Xanewok

Description

@Xanewok

This surfaced at rust-lang/rls#1463 (fixed in rust-lang/rls#1497).

The underlying data structure discerns a missing/"all" state in addition to actual set (possibly empty) of lines:

/// A set of lines in files.
///
/// It is represented as a multimap keyed on file names, with values a collection of
/// non-overlapping ranges sorted by their start point. An inner `None` is interpreted to mean all
/// lines in all files.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct FileLines(Option<HashMap<FileName, Vec<Range>>>);

whereas to_json_span only encodes a specified set of those changes (can't represent FileLines(None)):

/// Returns JSON representation as accepted by the `--file-lines JSON` arg.
pub fn to_json_spans(&self) -> Vec<JsonSpan> {
match &self.0 {
None => vec![],

I think we should either:

  1. panic/return err on None match in to_json_spans (since vec![] returned for FileLines(None) won't be parsed back into the FileLines(None) but rather FileLines(Some(HashMap::new))
  2. Somehow discern or accept null lines in --file-lines JSON and make to_json_spans() return Option<Vec<JsonSpan>>

Thoughts?

cc @jsgf @ljw1004

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPanic, non-idempotency, invalid code, etc.p-high

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions