Consider --preview flag for server subcommand (#12208)

## Summary

This PR removes the requirement of `--preview` flag to run the `ruff
server` and instead considers it to be an indicator to turn on preview
mode for the linter and the formatter.

resolves: #12161 

## Test Plan

Add test cases to assert the `preview` value is updated accordingly.

In an editor context, I used the local `ruff` executable in Neovim with
the `--preview` flag and verified that the preview-only violations are
being highlighted.

Running with:
```lua
require('lspconfig').ruff.setup({
  cmd = {
    '/Users/dhruv/work/astral/ruff/target/debug/ruff',
    'server',
    '--preview',
  },
})
```
The screenshot shows that `E502` is highlighted with the below config in
`pyproject.toml`:

<img width="877" alt="Screenshot 2024-07-17 at 16 43 09"
src="https://github.com/user-attachments/assets/c7016ef3-55b1-4a14-bbd3-a07b1bcdd323">
This commit is contained in:
Dhruv Manilawala 2024-07-18 11:05:01 +05:30 committed by GitHub
parent ebe5b06c95
commit 2e77b775b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 145 additions and 37 deletions

View file

@ -48,7 +48,7 @@ pub struct Server {
}
impl Server {
pub fn new(worker_threads: NonZeroUsize) -> crate::Result<Self> {
pub fn new(worker_threads: NonZeroUsize, preview: Option<bool>) -> crate::Result<Self> {
let connection = ConnectionInitializer::stdio();
let (id, init_params) = connection.initialize_start()?;
@ -70,14 +70,18 @@ impl Server {
crate::message::init_messenger(connection.make_sender());
let AllSettings {
global_settings,
mut workspace_settings,
} = AllSettings::from_value(
let mut all_settings = AllSettings::from_value(
init_params
.initialization_options
.unwrap_or_else(|| serde_json::Value::Object(serde_json::Map::default())),
);
if let Some(preview) = preview {
all_settings.set_preview(preview);
}
let AllSettings {
global_settings,
mut workspace_settings,
} = all_settings;
crate::trace::init_tracing(
connection.make_sender(),