Skip to content

Refactor: Consolidate document state management in Workspace #646

@jade-codes

Description

@jade-codes

Problem

The LSP layer duplicates state that should live in Workspace:

  • document_texts: HashMap<PathBuf, String> - tracked separately from workspace files
  • parse_errors: HashMap<PathBuf, Vec> - tracked separately from workspace files
  • Direct std::fs::read_to_string calls bypassing core abstractions

This violates separation of concerns - LSP should be a thin protocol adapter, not a state manager.

Implementation Plan

  • Add source_text: String to WorkspaceFile
  • Add errors: Vec to WorkspaceFile
  • Create FileLoader trait for abstraction (disk/memory/virtual sources)
  • Add update_from_text(path, text) method to Workspace
  • Remove document_texts from LspServer, use workspace.get_text(path)
  • Remove parse_errors from LspServer, use workspace.get_errors(path)
  • Remove direct std::fs calls from LSP layer

Benefits

  • Single source of truth for document state
  • LSP becomes a thin protocol adapter
  • Easier testing (mock FileLoader)
  • Better separation of concerns

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions