Skip to content

Commit

Permalink
Added textDocument/formatting support on lsp
Browse files Browse the repository at this point in the history
  • Loading branch information
redking00 committed Feb 10, 2025
1 parent 870a56d commit aa9aba0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
23 changes: 22 additions & 1 deletion client/lsp-server/notebook-lsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ const onIdeRequest = async (data: any) => {
else if (
data.method === 'textDocument/foldingRange' ||
data.method === 'textDocument/codeLens' ||
data.method === 'textDocument/semanticTokens/full'
data.method === 'textDocument/semanticTokens/full' ||
data.method === 'textDocument/formatting'
) {
const notebook = getNotebookByTextDocumentUri(data.params.textDocument.uri);
if (notebook !== undefined) {
Expand Down Expand Up @@ -312,6 +313,26 @@ const onDenoResponse = async (req: PendingRequest | undefined, data: any) => {
}
}
}
else if (req && (req.method === 'textDocument/formatting')) {
if (data.result && data.result.length > 0) {
const tdUri = (req.params as any).textDocument.uri;
if (tdUri) {
const notebook = getNotebookByTextDocumentUri(tdUri);
if (notebook) {
const td = notebook.textDocuments.find(d => d.uri === tdUri);
if (td) {
const startLine = getStartLine(notebook, tdUri)!;
data.result = data.result.map((r: any) => {
r.range.start.line -= startLine;
r.range.end.line -= startLine;
return r;
}).filter((r: any) => r.range.start.line >= 0 && r.range.start.line < (td.lines.length));
}
}
}
}
}

}
await ideIn.write(data);
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Visual Studio Code plugin for Deno lsp support on notebooks (+ NBTS serializer + DenoNBTS kernel)",
"author": "redking00 & Deno Land Inc.",
"license": "MIT",
"version": "1.0.23",
"version": "1.0.24",
"icon": "deno.png",
"galleryBanner": {
"color": "#3B3738",
Expand Down

0 comments on commit aa9aba0

Please sign in to comment.