Skip to content

Commit b9badb9

Browse files
authored
Merge branch 'main' into refactor/lexer
2 parents fb1d98d + adb7a9e commit b9badb9

File tree

6 files changed

+267
-0
lines changed

6 files changed

+267
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ Our current focus is on refining and enhancing these core features while buildin
3333
- [psteinroe](https://github.com/psteinroe)
3434
- [juleswritescode](https://github.com/juleswritescode)
3535

36+
## Development
37+
38+
### Using Nix
39+
40+
```bash
41+
nix develop
42+
docker-compose up -d
43+
```
44+
45+
### Using Docker
46+
47+
```bash
48+
docker-compose up -d
49+
```
50+
3651
## Acknowledgements
3752

3853
A big thanks to the following projects, without which this project wouldn't have been possible:

crates/pgt_configuration/src/analyser/linter/rules.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ impl Rules {
121121
}
122122
enabled_rules.difference(&disabled_rules).copied().collect()
123123
}
124+
#[doc = r" It returns the disabled rules by configuration."]
125+
pub fn as_disabled_rules(&self) -> FxHashSet<RuleFilter<'static>> {
126+
let mut disabled_rules = FxHashSet::default();
127+
if let Some(group) = self.safety.as_ref() {
128+
disabled_rules.extend(&group.get_disabled_rules());
129+
}
130+
disabled_rules
131+
}
124132
}
125133
#[derive(Clone, Debug, Default, Deserialize, Eq, Merge, PartialEq, Serialize)]
126134
#[cfg_attr(feature = "schema", derive(JsonSchema))]

crates/pgt_workspace/src/workspace/server/analyser.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,23 @@ impl<'a, 'b> LintVisitor<'a, 'b> {
6868

6969
fn finish(mut self) -> (FxHashSet<RuleFilter<'a>>, FxHashSet<RuleFilter<'a>>) {
7070
let has_only_filter = !self.only.is_empty();
71+
7172
if !has_only_filter {
7273
let enabled_rules = self
7374
.settings
7475
.as_linter_rules()
7576
.map(|rules| rules.as_enabled_rules())
7677
.unwrap_or_default();
7778
self.enabled_rules.extend(enabled_rules);
79+
80+
let disabled_rules = self
81+
.settings
82+
.as_linter_rules()
83+
.map(|rules| rules.as_disabled_rules())
84+
.unwrap_or_default();
85+
self.disabled_rules.extend(disabled_rules);
7886
}
87+
7988
(self.enabled_rules, self.disabled_rules)
8089
}
8190

@@ -127,3 +136,42 @@ impl RegistryVisitor for LintVisitor<'_, '_> {
127136
self.push_rule::<R>()
128137
}
129138
}
139+
140+
#[cfg(test)]
141+
mod tests {
142+
use pgt_analyse::RuleFilter;
143+
use pgt_configuration::{RuleConfiguration, Rules, analyser::Safety};
144+
145+
use crate::{
146+
settings::{LinterSettings, Settings},
147+
workspace::server::analyser::AnalyserVisitorBuilder,
148+
};
149+
150+
#[test]
151+
fn recognizes_disabled_rules() {
152+
let settings = Settings {
153+
linter: LinterSettings {
154+
rules: Some(Rules {
155+
safety: Some(Safety {
156+
ban_drop_column: Some(RuleConfiguration::Plain(
157+
pgt_configuration::RulePlainConfiguration::Off,
158+
)),
159+
..Default::default()
160+
}),
161+
..Default::default()
162+
}),
163+
..Default::default()
164+
},
165+
..Default::default()
166+
};
167+
168+
let (_, disabled_rules) = AnalyserVisitorBuilder::new(&settings)
169+
.with_linter_rules(&[], &[])
170+
.finish();
171+
172+
assert_eq!(
173+
disabled_rules,
174+
vec![RuleFilter::Rule("safety", "banDropColumn")]
175+
)
176+
}
177+
}

flake.lock

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
{
2+
description = "PostgreSQL Language Server Development Environment";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
rust-overlay = {
8+
url = "github:oxalica/rust-overlay";
9+
inputs.nixpkgs.follows = "nixpkgs";
10+
};
11+
};
12+
13+
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
14+
flake-utils.lib.eachDefaultSystem (system:
15+
let
16+
overlays = [ (import rust-overlay) ];
17+
pkgs = import nixpkgs {
18+
inherit system overlays;
19+
};
20+
21+
# Read rust-toolchain.toml to get the exact Rust version
22+
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
23+
24+
# Development dependencies
25+
buildInputs = with pkgs; [
26+
# Rust toolchain
27+
rustToolchain
28+
29+
# Node.js ecosystem
30+
bun
31+
nodejs_20
32+
33+
# Python for additional tooling
34+
python3
35+
python3Packages.pip
36+
37+
# System dependencies
38+
pkg-config
39+
openssl
40+
41+
# Build tools
42+
just
43+
git
44+
45+
# LSP and development tools
46+
rust-analyzer
47+
48+
# Additional tools that might be needed
49+
cmake
50+
gcc
51+
libiconv
52+
];
53+
54+
# Environment variables
55+
env = {
56+
RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library";
57+
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
58+
};
59+
60+
in
61+
{
62+
devShells.default = pkgs.mkShell {
63+
inherit buildInputs;
64+
65+
shellHook = ''
66+
echo "PostgreSQL Language Server Development Environment"
67+
echo "Available tools:"
68+
echo " • Rust $(rustc --version)"
69+
echo " • Node.js $(node --version)"
70+
echo " • Bun $(bun --version)"
71+
echo " • Just $(just --version)"
72+
echo ""
73+
echo "Development Commands:"
74+
echo " • just --list # Show tasks"
75+
echo " • cargo check # Check Rust"
76+
echo " • bun install # Install deps"
77+
echo ""
78+
echo "Use Docker for database:"
79+
echo " • docker-compose up -d"
80+
echo ""
81+
82+
# Set environment variables
83+
${pkgs.lib.concatStringsSep "\n"
84+
(pkgs.lib.mapAttrsToList (name: value: "export ${name}=\"${value}\"") env)}
85+
'';
86+
};
87+
88+
# Formatter for nix files
89+
formatter = pkgs.nixfmt-rfc-style;
90+
}
91+
);
92+
}

xtask/codegen/src/generate_configuration.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ fn generate_for_groups(
6161
let mut group_idents = Vec::with_capacity(groups.len());
6262
let mut group_strings = Vec::with_capacity(groups.len());
6363
let mut group_as_default_rules = Vec::with_capacity(groups.len());
64+
let mut group_as_disabled_rules = Vec::with_capacity(groups.len());
65+
6466
for (group, rules) in groups {
6567
let group_pascal_ident = quote::format_ident!("{}", &Case::Pascal.convert(group));
6668
let group_ident = quote::format_ident!("{}", group);
@@ -95,6 +97,12 @@ fn generate_for_groups(
9597
}
9698
});
9799

100+
group_as_disabled_rules.push(quote! {
101+
if let Some(group) = self.#group_ident.as_ref() {
102+
disabled_rules.extend(&group.get_disabled_rules());
103+
}
104+
});
105+
98106
group_pascal_idents.push(group_pascal_ident);
99107
group_idents.push(group_ident);
100108
group_strings.push(Literal::string(group));
@@ -246,6 +254,13 @@ fn generate_for_groups(
246254
#( #group_as_default_rules )*
247255
enabled_rules
248256
}
257+
258+
/// It returns the disabled rules by configuration.
259+
pub fn as_disabled_rules(&self) -> FxHashSet<RuleFilter<'static>> {
260+
let mut disabled_rules = FxHashSet::default();
261+
#( #group_as_disabled_rules )*
262+
disabled_rules
263+
}
249264
}
250265

251266
#( #struct_groups )*
@@ -358,6 +373,13 @@ fn generate_for_groups(
358373

359374
enabled_rules.difference(&disabled_rules).copied().collect()
360375
}
376+
377+
/// It returns the disabled rules by configuration.
378+
pub fn as_disabled_rules(&self) -> FxHashSet<RuleFilter<'static>> {
379+
let mut disabled_rules = FxHashSet::default();
380+
#( #group_as_disabled_rules )*
381+
disabled_rules
382+
}
361383
}
362384

363385
#( #struct_groups )*

0 commit comments

Comments
 (0)