Skip to content
Prev Previous commit
Next Next commit
ok
  • Loading branch information
juleswritescode committed Apr 11, 2025
commit 6d772cf2b552d7f017dcbbe40b064c98af422acb
40 changes: 21 additions & 19 deletions crates/pgt_workspace/src/workspace/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub(super) struct WorkspaceServer {
/// Stores the schema cache for this workspace
schema_cache: SchemaCacheManager,

parsers: DashMap<PgTPath, ParsedStatements>,
parsed_documents: DashMap<PgTPath, ParsedStatements>,

connection: RwLock<DbConnection>,
}
Expand All @@ -84,7 +84,7 @@ impl WorkspaceServer {
pub(crate) fn new() -> Self {
Self {
settings: RwLock::default(),
parsers: DashMap::default(),
parsed_documents: DashMap::default(),
schema_cache: SchemaCacheManager::default(),
connection: RwLock::default(),
}
Expand Down Expand Up @@ -182,16 +182,18 @@ impl Workspace for WorkspaceServer {
/// Add a new file to the workspace
#[tracing::instrument(level = "info", skip_all, fields(path = params.path.as_path().as_os_str().to_str()), err)]
fn open_file(&self, params: OpenFileParams) -> Result<(), WorkspaceError> {
self.parsers.entry(params.path.clone()).or_insert_with(|| {
ParsedStatements::new(params.path.clone(), params.content, params.version)
});
self.parsed_documents
.entry(params.path.clone())
.or_insert_with(|| {
ParsedStatements::new(params.path.clone(), params.content, params.version)
});

Ok(())
}

/// Remove a file from the workspace
fn close_file(&self, params: super::CloseFileParams) -> Result<(), WorkspaceError> {
self.parsers
self.parsed_documents
.remove(&params.path)
.ok_or_else(WorkspaceError::not_found)?;

Expand All @@ -204,14 +206,14 @@ impl Workspace for WorkspaceServer {
version = params.version
), err)]
fn change_file(&self, params: super::ChangeFileParams) -> Result<(), WorkspaceError> {
let mut parser = self
.parsers
.entry(params.path.clone())
.or_insert(ParsedStatements::new(
params.path.clone(),
"".to_string(),
params.version,
));
let mut parser =
self.parsed_documents
.entry(params.path.clone())
.or_insert(ParsedStatements::new(
params.path.clone(),
"".to_string(),
params.version,
));

parser.apply_change(params);

Expand All @@ -224,7 +226,7 @@ impl Workspace for WorkspaceServer {

fn get_file_content(&self, params: GetFileContentParams) -> Result<String, WorkspaceError> {
let document = self
.parsers
.parsed_documents
.get(&params.path)
.ok_or(WorkspaceError::not_found())?;
Ok(document.get_document_content().to_string())
Expand All @@ -239,7 +241,7 @@ impl Workspace for WorkspaceServer {
params: code_actions::CodeActionsParams,
) -> Result<code_actions::CodeActionsResult, WorkspaceError> {
let parser = self
.parsers
.parsed_documents
.get(&params.path)
.ok_or(WorkspaceError::not_found())?;

Expand Down Expand Up @@ -283,7 +285,7 @@ impl Workspace for WorkspaceServer {
params: ExecuteStatementParams,
) -> Result<ExecuteStatementResult, WorkspaceError> {
let parser = self
.parsers
.parsed_documents
.get(&params.path)
.ok_or(WorkspaceError::not_found())?;

Expand Down Expand Up @@ -351,7 +353,7 @@ impl Workspace for WorkspaceServer {
});

let parser = self
.parsers
.parsed_documents
.get(&params.path)
.ok_or(WorkspaceError::not_found())?;

Expand Down Expand Up @@ -468,7 +470,7 @@ impl Workspace for WorkspaceServer {
params: GetCompletionsParams,
) -> Result<CompletionsResult, WorkspaceError> {
let parser = self
.parsers
.parsed_documents
.get(&params.path)
.ok_or(WorkspaceError::not_found())?;

Expand Down