Skip to content

Commit 8b6d451

Browse files
changes
1 parent 6310058 commit 8b6d451

File tree

8 files changed

+70
-37
lines changed

8 files changed

+70
-37
lines changed

crates/pg_cli/src/commands/daemon.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ pub(crate) fn lsp_proxy(
111111
log_file_name_prefix: Option<String>,
112112
) -> Result<(), CliDiagnostic> {
113113
let rt = Runtime::new()?;
114+
println!("Starting LSP Proxy…");
114115
rt.block_on(start_lsp_proxy(
115116
&rt,
116117
config_path,

crates/pg_lsp_new/src/handlers/text_document.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use pg_workspace_new::workspace::{
55
ChangeFileParams, ChangeParams, CloseFileParams, GetFileContentParams, OpenFileParams,
66
};
77
use tower_lsp::lsp_types;
8-
use tracing::{error, field};
8+
use tracing::{error, field, info};
99

1010
/// Handler for `textDocument/didOpen` LSP notification
1111
#[tracing::instrument(
@@ -43,36 +43,48 @@ pub(crate) async fn did_open(
4343
}
4444

4545
// Handler for `textDocument/didChange` LSP notification
46-
#[tracing::instrument(level = "debug", skip_all, fields(url = field::display(&params.text_document.uri), version = params.text_document.version), err)]
46+
#[tracing::instrument(level = "info", skip_all, fields(url = field::display(&params.text_document.uri), version = params.text_document.version), err)]
4747
pub(crate) async fn did_change(
4848
session: &Session,
4949
params: lsp_types::DidChangeTextDocumentParams,
5050
) -> Result<()> {
5151
let url = params.text_document.uri;
5252
let version = params.text_document.version;
5353

54+
info!("Reading LSP Path...");
55+
5456
let pglsp_path = session.file_path(&url)?;
5557

58+
info!("Getting file content...");
59+
5660
// we need to keep the documents here too for the line index
5761
let old_text = session.workspace.get_file_content(GetFileContentParams {
5862
path: pglsp_path.clone(),
5963
})?;
6064

65+
info!("Finding start…");
66+
6167
let start = params
6268
.content_changes
6369
.iter()
6470
.rev()
6571
.position(|change| change.range.is_none())
6672
.map_or(0, |idx| params.content_changes.len() - idx - 1);
6773

74+
info!("Getting finalized text...");
75+
6876
let text = apply_document_changes(
6977
session.position_encoding(),
7078
old_text,
7179
&params.content_changes[start..],
7280
);
7381

82+
info!("Creating new doc…");
83+
7484
let new_doc = Document::new(version, &text);
7585

86+
info!("Changing File in Workspace...");
87+
7688
session.workspace.change_file(ChangeFileParams {
7789
path: pglsp_path,
7890
version,
@@ -87,8 +99,12 @@ pub(crate) async fn did_change(
8799
.collect(),
88100
})?;
89101

102+
info!("Inserting document...");
103+
90104
session.insert_document(url.clone(), new_doc);
91105

106+
info!("Updating diagnostics...");
107+
92108
if let Err(err) = session.update_diagnostics(url).await {
93109
error!("Failed to update diagnostics: {}", err);
94110
}

crates/pg_lsp_new/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{fs::File, path::PathBuf, str::FromStr};
22

33
use pg_lsp_new::ServerFactory;
4+
use tower_lsp::Server;
45
use tracing_subscriber::fmt::format::FmtSpan;
56

67
#[tokio::main]
@@ -27,10 +28,12 @@ async fn main() -> anyhow::Result<()> {
2728

2829
tracing::info!("Starting server.");
2930

30-
ServerFactory::new(true)
31+
ServerFactory::new(false)
3132
.create(Some(config_path))
3233
.accept(stdin, stdout)
3334
.await;
3435

36+
tracing::info!("Shut down server.");
37+
3538
Ok(())
3639
}

crates/pg_lsp_new/src/server.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl LSPServer {
106106
impl LanguageServer for LSPServer {
107107
#[allow(deprecated)]
108108
#[tracing::instrument(
109-
level = "trace",
109+
level = "info",
110110
skip_all,
111111
fields(
112112
root_uri = params.root_uri.as_ref().map(display),
@@ -143,7 +143,7 @@ impl LanguageServer for LSPServer {
143143
Ok(init)
144144
}
145145

146-
#[tracing::instrument(level = "trace", skip(self))]
146+
#[tracing::instrument(level = "info", skip_all)]
147147
async fn initialized(&self, params: InitializedParams) {
148148
let _ = params;
149149

@@ -163,19 +163,20 @@ impl LanguageServer for LSPServer {
163163
self.session.update_all_diagnostics().await;
164164
}
165165

166+
#[tracing::instrument(level = "info", skip(self))]
166167
async fn shutdown(&self) -> LspResult<()> {
167168
Ok(())
168169
}
169170

170-
#[tracing::instrument(level = "trace", skip(self))]
171+
#[tracing::instrument(level = "info", skip(self))]
171172
async fn did_change_configuration(&self, params: DidChangeConfigurationParams) {
172173
let _ = params;
173174
self.session.load_workspace_settings().await;
174175
self.setup_capabilities().await;
175176
self.session.update_all_diagnostics().await;
176177
}
177178

178-
#[tracing::instrument(level = "trace", skip(self))]
179+
#[tracing::instrument(level = "info", skip(self))]
179180
async fn did_change_watched_files(&self, params: DidChangeWatchedFilesParams) {
180181
let file_paths = params
181182
.changes
@@ -209,31 +210,35 @@ impl LanguageServer for LSPServer {
209210
}
210211
}
211212

213+
#[tracing::instrument(level = "info", skip(self))]
212214
async fn did_open(&self, params: DidOpenTextDocumentParams) {
213215
handlers::text_document::did_open(&self.session, params)
214216
.await
215217
.ok();
216218
}
217219

220+
#[tracing::instrument(level = "info", skip(self, params))]
218221
async fn did_change(&self, params: DidChangeTextDocumentParams) {
219-
handlers::text_document::did_change(&self.session, params)
220-
.await
221-
.ok();
222+
if let Err(e) = handlers::text_document::did_change(&self.session, params).await {
223+
error!("{}", e);
224+
};
222225
}
223226

227+
#[tracing::instrument(level = "info", skip(self))]
224228
async fn did_save(&self, params: DidSaveTextDocumentParams) {
225229
// handlers::text_document::did_save(&self.session, params)
226230
// .await
227231
// .ok();
228232
}
229233

234+
#[tracing::instrument(level = "info", skip(self))]
230235
async fn did_close(&self, params: DidCloseTextDocumentParams) {
231236
handlers::text_document::did_close(&self.session, params)
232237
.await
233238
.ok();
234239
}
235240

236-
#[tracing::instrument(level = "trace", skip(self))]
241+
#[tracing::instrument(level = "info", skip(self))]
237242
async fn completion(&self, params: CompletionParams) -> LspResult<Option<CompletionResponse>> {
238243
match handlers::completions::get_completions(&self.session, params) {
239244
Ok(result) => LspResult::Ok(Some(result)),

editors/code/package-lock.json

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

editors/code/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"anser": "^2.1.1",
4848
"d3": "^7.8.5",
4949
"d3-graphviz": "^5.0.2",
50-
"vscode-languageclient": "^8.1.0"
50+
"vscode-languageclient": "9.0.1"
5151
},
5252
"devDependencies": {
5353
"@tsconfig/strictest": "^2.0.1",

editors/code/src/main.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ExtensionContext } from 'vscode';
1+
import { type ExtensionContext, window } from 'vscode';
22

33
import {
44
type Executable,
@@ -9,11 +9,11 @@ import {
99

1010
let client: LanguageClient;
1111

12-
export function activate(_context: ExtensionContext) {
12+
export async function activate(_context: ExtensionContext) {
1313
// If the extension is launched in debug mode then the debug server options are used
1414
// Otherwise the run options are used
1515
const run: Executable = {
16-
command: 'pglsp'
16+
command: 'pglsp_new'
1717
};
1818

1919
// const outputChannel = window.createOutputChannel('postgres_lsp');
@@ -26,14 +26,15 @@ export function activate(_context: ExtensionContext) {
2626
// Options to control the language client
2727
const clientOptions: LanguageClientOptions = {
2828
// Register the server for plain text documents
29-
documentSelector: [{ scheme: 'file', language: 'sql' }]
29+
documentSelector: [{ scheme: 'file', language: 'sql' }],
30+
traceOutputChannel: window.createOutputChannel('Postgres LSP Tracing', { log: true })
3031
};
3132

3233
// Create the language client and start the client.
3334
client = new LanguageClient('postgres_lsp', 'Postgres LSP', serverOptions, clientOptions);
3435

3536
// Start the client. This will also launch the server
36-
void client.start();
37+
await client.start();
3738
}
3839

3940
export function deactivate(): Thenable<void> | undefined {

xtask/src/install.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ fn install_client(sh: &Shell, client_opt: ClientOpt) -> anyhow::Result<()> {
137137
}
138138

139139
fn install_server(sh: &Shell) -> anyhow::Result<()> {
140-
let cmd = cmd!(sh, "cargo install --path crates/pg_lsp --locked --force");
140+
let cmd = cmd!(
141+
sh,
142+
"cargo install --path crates/pg_lsp_new --locked --force"
143+
);
141144
cmd.run()?;
142145
Ok(())
143146
}

0 commit comments

Comments
 (0)