Skip to content

Commit f13d2aa

Browse files
Merge branch 'main' into fix/tree-sitter-errors
2 parents 8521f6d + 88653d1 commit f13d2aa

File tree

31 files changed

+813
-138
lines changed

31 files changed

+813
-138
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,20 @@ Once the parser is stable, and a robust and scalable data model is implemented,
4444
Add the postgres_lsp executable to your path, and add the following to your config to use it.
4545

4646
```lua
47+
local util = require 'lspconfig.util'
48+
local lspconfig = require 'lspconfig'
49+
4750
require('lspconfig.configs').postgres_lsp = {
4851
default_config = {
4952
name = 'postgres_lsp',
50-
cmd = {'postgres_lsp'},
51-
filetypes = {'sql'},
53+
cmd = { 'postgres_lsp' },
54+
filetypes = { 'sql' },
5255
single_file_support = true,
53-
root_dir = util.root_pattern 'root-file.txt'
54-
}
56+
root_dir = util.root_pattern 'root-file.txt',
57+
},
5558
}
5659

57-
lsp.configure("postgres_lsp", {force_setup = true})
60+
lspconfig.postgres_lsp.setup { force_setup = true }
5861
```
5962

6063
### Building from source

crates/pg_cli/src/changed.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use crate::CliDiagnostic;
2+
use pg_configuration::PartialConfiguration;
3+
use pg_fs::FileSystem;
4+
use pg_workspace_new::DynRef;
5+
use std::ffi::OsString;
6+
7+
pub(crate) fn get_changed_files(
8+
fs: &DynRef<'_, dyn FileSystem>,
9+
configuration: &PartialConfiguration,
10+
since: Option<&str>,
11+
) -> Result<Vec<OsString>, CliDiagnostic> {
12+
let default_branch = configuration
13+
.vcs
14+
.as_ref()
15+
.and_then(|v| v.default_branch.as_ref());
16+
17+
let base = match (since, default_branch) {
18+
(Some(since), Some(_)) => since,
19+
(Some(since), None) => since,
20+
(None, Some(branch)) => branch,
21+
(None, None) => return Err(CliDiagnostic::incompatible_end_configuration("The `--changed` flag was set, but couldn't determine the base to compare against. Either set configuration.vcs.default_branch or use the --since argument.")),
22+
};
23+
24+
let changed_files = fs.get_changed_files(base)?;
25+
26+
let filtered_changed_files = changed_files.iter().map(OsString::from).collect::<Vec<_>>();
27+
28+
Ok(filtered_changed_files)
29+
}
30+
31+
pub(crate) fn get_staged_files(
32+
fs: &DynRef<'_, dyn FileSystem>,
33+
) -> Result<Vec<OsString>, CliDiagnostic> {
34+
let staged_files = fs.get_staged_files()?;
35+
36+
let filtered_staged_files = staged_files.iter().map(OsString::from).collect::<Vec<_>>();
37+
38+
Ok(filtered_staged_files)
39+
}

crates/pg_cli/src/commands/check.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// use super::{determine_fix_file_mode, FixFileModeOptions, LoadEditorConfig};
2+
use crate::cli_options::CliOptions;
3+
// use crate::commands::{get_files_to_process_with_cli_options, CommandRunner};
4+
use crate::{CliDiagnostic, Execution, TraversalMode};
5+
use pg_configuration::PartialConfiguration;
6+
use pg_console::Console;
7+
// use biome_deserialize::Merge;
8+
use pg_fs::FileSystem;
9+
use pg_workspace_new::{configuration::LoadedConfiguration, DynRef, Workspace, WorkspaceError};
10+
use std::ffi::OsString;
11+
12+
use super::{determine_fix_file_mode, get_files_to_process_with_cli_options, CommandRunner};
13+
14+
pub(crate) struct CheckCommandPayload {
15+
pub(crate) write: bool,
16+
pub(crate) fix: bool,
17+
pub(crate) unsafe_: bool,
18+
pub(crate) configuration: Option<PartialConfiguration>,
19+
pub(crate) paths: Vec<OsString>,
20+
pub(crate) stdin_file_path: Option<String>,
21+
pub(crate) staged: bool,
22+
pub(crate) changed: bool,
23+
pub(crate) since: Option<String>,
24+
}
25+
26+
impl CommandRunner for CheckCommandPayload {
27+
const COMMAND_NAME: &'static str = "check";
28+
29+
fn merge_configuration(
30+
&mut self,
31+
loaded_configuration: LoadedConfiguration,
32+
fs: &DynRef<'_, dyn FileSystem>,
33+
console: &mut dyn Console,
34+
) -> Result<PartialConfiguration, WorkspaceError> {
35+
let LoadedConfiguration { configuration, .. } = loaded_configuration;
36+
37+
Ok(configuration)
38+
}
39+
40+
fn get_files_to_process(
41+
&self,
42+
fs: &DynRef<'_, dyn FileSystem>,
43+
configuration: &PartialConfiguration,
44+
) -> Result<Vec<OsString>, CliDiagnostic> {
45+
let paths = get_files_to_process_with_cli_options(
46+
self.since.as_deref(),
47+
self.changed,
48+
self.staged,
49+
fs,
50+
configuration,
51+
)?
52+
.unwrap_or(self.paths.clone());
53+
54+
Ok(paths)
55+
}
56+
57+
fn get_stdin_file_path(&self) -> Option<&str> {
58+
self.stdin_file_path.as_deref()
59+
}
60+
61+
fn should_write(&self) -> bool {
62+
self.write || self.fix
63+
}
64+
65+
fn get_execution(
66+
&self,
67+
cli_options: &CliOptions,
68+
console: &mut dyn Console,
69+
_workspace: &dyn Workspace,
70+
) -> Result<Execution, CliDiagnostic> {
71+
Ok(Execution::new(TraversalMode::Check {
72+
stdin: self.get_stdin(console)?,
73+
vcs_targeted: (self.staged, self.changed).into(),
74+
})
75+
.set_report(cli_options))
76+
}
77+
}

crates/pg_cli/src/commands/daemon.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,13 @@ pub(crate) fn read_most_recent_log_file(
206206
/// `pglsp-logs/server.log.yyyy-MM-dd-HH` files inside the system temporary
207207
/// directory)
208208
fn setup_tracing_subscriber(log_path: Option<PathBuf>, log_file_name_prefix: Option<String>) {
209-
let biome_log_path = log_path.unwrap_or(pg_fs::ensure_cache_dir().join("pglsp-logs"));
209+
let pglsp_log_path = log_path.unwrap_or(pg_fs::ensure_cache_dir().join("pglsp-logs"));
210210
let appender_builder = tracing_appender::rolling::RollingFileAppender::builder();
211211
let file_appender = appender_builder
212212
.filename_prefix(log_file_name_prefix.unwrap_or(String::from("server.log")))
213213
.max_log_files(7)
214214
.rotation(Rotation::HOURLY)
215-
.build(biome_log_path)
215+
.build(pglsp_log_path)
216216
.expect("Failed to start the logger for the daemon.");
217217

218218
registry()
@@ -241,7 +241,7 @@ pub fn default_pglsp_log_path() -> PathBuf {
241241
/// - All spans and events at level debug in crates whose name starts with `biome`
242242
struct LoggingFilter;
243243

244-
/// Tracing filter used for spans emitted by `biome*` crates
244+
/// Tracing filter used for spans emitted by `pglsp*` crates
245245
const SELF_FILTER: LevelFilter = if cfg!(debug_assertions) {
246246
LevelFilter::TRACE
247247
} else {
@@ -250,7 +250,7 @@ const SELF_FILTER: LevelFilter = if cfg!(debug_assertions) {
250250

251251
impl LoggingFilter {
252252
fn is_enabled(&self, meta: &Metadata<'_>) -> bool {
253-
let filter = if meta.target().starts_with("biome") {
253+
let filter = if meta.target().starts_with("pglsp") {
254254
SELF_FILTER
255255
} else {
256256
LevelFilter::INFO

0 commit comments

Comments
 (0)