Skip to content

Commit 1252436

Browse files
committed
Merge branch 'main' into dhruv/background-request-handler
2 parents a1fa874 + e212dc2 commit 1252436

File tree

7 files changed

+36
-45
lines changed

7 files changed

+36
-45
lines changed

crates/ty_ide/src/hover.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl fmt::Display for DisplayHoverContent<'_, '_> {
118118
match self.content {
119119
HoverContent::Type(ty) => self
120120
.kind
121-
.fenced_code_block(ty.display(self.db), "text")
121+
.fenced_code_block(ty.display(self.db), "python")
122122
.fmt(f),
123123
}
124124
}
@@ -148,7 +148,7 @@ mod tests {
148148
assert_snapshot!(test.hover(), @r"
149149
Literal[10]
150150
---------------------------------------------
151-
```text
151+
```python
152152
Literal[10]
153153
```
154154
---------------------------------------------
@@ -184,7 +184,7 @@ mod tests {
184184
assert_snapshot!(test.hover(), @r"
185185
int
186186
---------------------------------------------
187-
```text
187+
```python
188188
int
189189
```
190190
---------------------------------------------
@@ -214,7 +214,7 @@ mod tests {
214214
assert_snapshot!(test.hover(), @r"
215215
def foo(a, b) -> Unknown
216216
---------------------------------------------
217-
```text
217+
```python
218218
def foo(a, b) -> Unknown
219219
```
220220
---------------------------------------------
@@ -243,7 +243,7 @@ mod tests {
243243
assert_snapshot!(test.hover(), @r"
244244
bool
245245
---------------------------------------------
246-
```text
246+
```python
247247
bool
248248
```
249249
---------------------------------------------
@@ -274,7 +274,7 @@ mod tests {
274274
assert_snapshot!(test.hover(), @r"
275275
Literal[123]
276276
---------------------------------------------
277-
```text
277+
```python
278278
Literal[123]
279279
```
280280
---------------------------------------------
@@ -312,7 +312,7 @@ mod tests {
312312
assert_snapshot!(test.hover(), @r"
313313
(def foo(a, b) -> Unknown) | (def bar(a, b) -> Unknown)
314314
---------------------------------------------
315-
```text
315+
```python
316316
(def foo(a, b) -> Unknown) | (def bar(a, b) -> Unknown)
317317
```
318318
---------------------------------------------
@@ -344,7 +344,7 @@ mod tests {
344344
assert_snapshot!(test.hover(), @r"
345345
<module 'lib'>
346346
---------------------------------------------
347-
```text
347+
```python
348348
<module 'lib'>
349349
```
350350
---------------------------------------------
@@ -373,7 +373,7 @@ mod tests {
373373
assert_snapshot!(test.hover(), @r"
374374
T
375375
---------------------------------------------
376-
```text
376+
```python
377377
T
378378
```
379379
---------------------------------------------
@@ -399,7 +399,7 @@ mod tests {
399399
assert_snapshot!(test.hover(), @r"
400400
@Todo
401401
---------------------------------------------
402-
```text
402+
```python
403403
@Todo
404404
```
405405
---------------------------------------------
@@ -425,7 +425,7 @@ mod tests {
425425
assert_snapshot!(test.hover(), @r"
426426
@Todo
427427
---------------------------------------------
428-
```text
428+
```python
429429
@Todo
430430
```
431431
---------------------------------------------
@@ -451,7 +451,7 @@ mod tests {
451451
assert_snapshot!(test.hover(), @r"
452452
Literal[1]
453453
---------------------------------------------
454-
```text
454+
```python
455455
Literal[1]
456456
```
457457
---------------------------------------------
@@ -482,7 +482,7 @@ mod tests {
482482
assert_snapshot!(test.hover(), @r"
483483
Literal[1]
484484
---------------------------------------------
485-
```text
485+
```python
486486
Literal[1]
487487
```
488488
---------------------------------------------
@@ -512,7 +512,7 @@ mod tests {
512512
assert_snapshot!(test.hover(), @r"
513513
Literal[2]
514514
---------------------------------------------
515-
```text
515+
```python
516516
Literal[2]
517517
```
518518
---------------------------------------------
@@ -545,7 +545,7 @@ mod tests {
545545
assert_snapshot!(test.hover(), @r"
546546
Unknown | Literal[1]
547547
---------------------------------------------
548-
```text
548+
```python
549549
Unknown | Literal[1]
550550
```
551551
---------------------------------------------
@@ -574,7 +574,7 @@ mod tests {
574574
assert_snapshot!(test.hover(), @r"
575575
int
576576
---------------------------------------------
577-
```text
577+
```python
578578
int
579579
```
580580
---------------------------------------------
@@ -602,7 +602,7 @@ mod tests {
602602
assert_snapshot!(test.hover(), @r"
603603
Literal[1]
604604
---------------------------------------------
605-
```text
605+
```python
606606
Literal[1]
607607
```
608608
---------------------------------------------
@@ -631,7 +631,7 @@ mod tests {
631631
assert_snapshot!(test.hover(), @r"
632632
int
633633
---------------------------------------------
634-
```text
634+
```python
635635
int
636636
```
637637
---------------------------------------------
@@ -661,7 +661,7 @@ mod tests {
661661
assert_snapshot!(test.hover(), @r"
662662
str
663663
---------------------------------------------
664-
```text
664+
```python
665665
str
666666
```
667667
---------------------------------------------

crates/ty_python_semantic/resources/mdtest/snapshots/dataclasses.md_-_Dataclasses_-_`dataclasses.KW_ONLY…_(dd1b8f2f71487f16).snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ expression: snapshot
44
---
55
---
66
mdtest name: dataclasses.md - Dataclasses - `dataclasses.KW_ONLY`
7-
mdtest path: crates/ty_python_semantic/resources/mdtest/dataclasses.md
7+
mdtest path: crates/ty_python_semantic/resources/mdtest/dataclasses/dataclasses.md
88
---
99

1010
# Python source files

crates/ty_server/src/logging.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,24 @@
44
//! are written to `stderr` by default, which should appear in the logs for most LSP clients. A
55
//! `logFile` path can also be specified in the settings, and output will be directed there
66
//! instead.
7-
use std::path::{Path, PathBuf};
8-
use std::str::FromStr;
97
use std::sync::Arc;
108

9+
use ruff_db::system::{SystemPath, SystemPathBuf};
1110
use serde::Deserialize;
1211
use tracing::level_filters::LevelFilter;
1312
use tracing_subscriber::Layer;
1413
use tracing_subscriber::fmt::time::ChronoLocal;
1514
use tracing_subscriber::fmt::writer::BoxMakeWriter;
1615
use tracing_subscriber::layer::SubscriberExt;
1716

18-
pub(crate) fn init_logging(log_level: LogLevel, log_file: Option<&Path>) {
17+
pub(crate) fn init_logging(log_level: LogLevel, log_file: Option<&SystemPath>) {
1918
let log_file = log_file
2019
.map(|path| {
2120
// this expands `logFile` so that tildes and environment variables
2221
// are replaced with their values, if possible.
23-
if let Some(expanded) = shellexpand::full(&path.to_string_lossy())
22+
if let Some(expanded) = shellexpand::full(&path.to_string())
2423
.ok()
25-
.and_then(|path| PathBuf::from_str(&path).ok())
24+
.map(|path| SystemPathBuf::from(&*path))
2625
{
2726
expanded
2827
} else {
@@ -33,14 +32,11 @@ pub(crate) fn init_logging(log_level: LogLevel, log_file: Option<&Path>) {
3332
std::fs::OpenOptions::new()
3433
.create(true)
3534
.append(true)
36-
.open(&path)
35+
.open(path.as_std_path())
3736
.map_err(|err| {
3837
#[expect(clippy::print_stderr)]
3938
{
40-
eprintln!(
41-
"Failed to open file at {} for logging: {err}",
42-
path.display()
43-
);
39+
eprintln!("Failed to open file at {path} for logging: {err}");
4440
}
4541
})
4642
.ok()

crates/ty_server/src/session.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use std::collections::{BTreeMap, VecDeque};
44
use std::ops::{Deref, DerefMut};
55
use std::panic::AssertUnwindSafe;
6-
use std::path::{Path, PathBuf};
76
use std::sync::Arc;
87

98
use anyhow::{Context, anyhow};
@@ -244,14 +243,7 @@ impl Session {
244243
// In the future, index the workspace directories to find all projects
245244
// and create a project database for each.
246245
let system = LSPSystem::new(self.index.as_ref().unwrap().clone());
247-
248-
let Some(system_path) = SystemPath::from_std_path(workspace.root()) else {
249-
tracing::warn!(
250-
"Ignore workspace `{}` because it's root contains non UTF8 characters",
251-
workspace.root().display()
252-
);
253-
continue;
254-
};
246+
let system_path = workspace.root();
255247

256248
let root = system_path.to_path_buf();
257249
let project = ProjectMetadata::discover(&root, &system)
@@ -504,11 +496,15 @@ impl Workspaces {
504496
.to_file_path()
505497
.map_err(|()| anyhow!("Workspace URL is not a file or directory: {url:?}"))?;
506498

499+
// Realistically I don't think this can fail because we got the path from a Url
500+
let system_path = SystemPathBuf::from_path_buf(path)
501+
.map_err(|_| anyhow!("Workspace URL is not valid UTF8"))?;
502+
507503
self.workspaces.insert(
508504
url,
509505
Workspace {
510506
options,
511-
root: path,
507+
root: system_path,
512508
},
513509
);
514510

@@ -551,12 +547,12 @@ impl<'a> IntoIterator for &'a Workspaces {
551547

552548
#[derive(Debug)]
553549
pub(crate) struct Workspace {
554-
root: PathBuf,
550+
root: SystemPathBuf,
555551
options: ClientOptions,
556552
}
557553

558554
impl Workspace {
559-
pub(crate) fn root(&self) -> &Path {
555+
pub(crate) fn root(&self) -> &SystemPath {
560556
&self.root
561557
}
562558
}

crates/ty_server/src/session/options.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use std::path::PathBuf;
2-
31
use lsp_types::Url;
2+
use ruff_db::system::SystemPathBuf;
43
use rustc_hash::FxHashMap;
54
use serde::Deserialize;
65

@@ -89,7 +88,7 @@ pub(crate) struct TracingOptions {
8988
pub(crate) log_level: Option<LogLevel>,
9089

9190
/// Path to the log file - tildes and environment variables are supported.
92-
pub(crate) log_file: Option<PathBuf>,
91+
pub(crate) log_file: Option<SystemPathBuf>,
9392
}
9493

9594
/// This is the exact schema for initialization options sent in by the client during

0 commit comments

Comments
 (0)