Skip to content

Commit bb0fc57

Browse files
committed
Add CI
1 parent 731abef commit bb0fc57

4 files changed

Lines changed: 71 additions & 27 deletions

File tree

.github/workflows/ci.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
check:
14+
name: Check
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: dtolnay/rust-toolchain@stable
19+
- uses: Swatinem/rust-cache@v2
20+
- run: cargo check
21+
22+
test:
23+
name: Test
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: dtolnay/rust-toolchain@stable
28+
- uses: Swatinem/rust-cache@v2
29+
- run: cargo test
30+
31+
fmt:
32+
name: Formatting
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: dtolnay/rust-toolchain@stable
37+
with:
38+
components: rustfmt
39+
- run: cargo fmt --check
40+
41+
clippy:
42+
name: Clippy
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v4
46+
- uses: dtolnay/rust-toolchain@stable
47+
with:
48+
components: clippy
49+
- uses: Swatinem/rust-cache@v2
50+
- run: cargo clippy -- -D warnings

src/lib.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,10 @@ impl LanguageServer for Backend {
124124
async fn did_change(&self, params: DidChangeTextDocumentParams) {
125125
let uri = params.text_document.uri.to_string();
126126

127-
if let Some(change) = params.content_changes.first() {
128-
if let Ok(mut files) = self.open_files.lock() {
127+
if let Some(change) = params.content_changes.first()
128+
&& let Ok(mut files) = self.open_files.lock() {
129129
files.insert(uri, change.text.clone());
130130
}
131-
}
132131
}
133132

134133
async fn did_close(&self, params: DidCloseTextDocumentParams) {
@@ -143,7 +142,11 @@ impl LanguageServer for Backend {
143142
}
144143

145144
async fn hover(&self, params: HoverParams) -> Result<Option<Hover>> {
146-
let uri = params.text_document_position_params.text_document.uri.to_string();
145+
let uri = params
146+
.text_document_position_params
147+
.text_document
148+
.uri
149+
.to_string();
147150
let position = params.text_document_position_params.position;
148151

149152
let content = if let Ok(files) = self.open_files.lock() {
@@ -152,34 +155,27 @@ impl LanguageServer for Backend {
152155
None
153156
};
154157

155-
if let Some(content) = content {
156-
if let Some(word) = self.get_word_at_position(&content, position) {
157-
if word == "PHPantom" {
158+
if let Some(content) = content
159+
&& let Some(word) = self.get_word_at_position(&content, position)
160+
&& word == "PHPantom" {
158161
return Ok(Some(Hover {
159162
contents: HoverContents::Scalar(MarkedString::String(
160163
"Welcome to PHPantomLSP!".to_string(),
161164
)),
162165
range: None,
163166
}));
164167
}
165-
}
166-
}
167168

168169
Ok(None)
169170
}
170171

171-
async fn completion(
172-
&self,
173-
_params: CompletionParams,
174-
) -> Result<Option<CompletionResponse>> {
175-
Ok(Some(CompletionResponse::Array(vec![
176-
CompletionItem {
177-
label: "PHPantomLSP".to_string(),
178-
kind: Some(CompletionItemKind::TEXT),
179-
detail: Some("PHPantomLSP completion".to_string()),
180-
insert_text: Some("PHPantomLSP".to_string()),
181-
..CompletionItem::default()
182-
},
183-
])))
172+
async fn completion(&self, _params: CompletionParams) -> Result<Option<CompletionResponse>> {
173+
Ok(Some(CompletionResponse::Array(vec![CompletionItem {
174+
label: "PHPantomLSP".to_string(),
175+
kind: Some(CompletionItemKind::TEXT),
176+
detail: Some("PHPantomLSP completion".to_string()),
177+
insert_text: Some("PHPantomLSP".to_string()),
178+
..CompletionItem::default()
179+
}])))
184180
}
185181
}

src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ async fn main() {
88
let stdin = tokio::io::stdin();
99
let stdout = tokio::io::stdout();
1010

11-
let (service, socket) = LspService::new(|client| Backend::new(client));
11+
let (service, socket) = LspService::new(Backend::new);
1212

13-
Server::new(stdin, stdout, socket)
14-
.serve(service)
15-
.await;
13+
Server::new(stdin, stdout, socket).serve(service).await;
1614
}

tests/integration_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use phpantom_lsp::Backend;
2-
use tower_lsp::lsp_types::*;
32
use tower_lsp::LanguageServer;
3+
use tower_lsp::lsp_types::*;
44

55
fn create_test_backend() -> Backend {
66
Backend::new_test()

0 commit comments

Comments
 (0)