Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
feat: add CodeLens for deno cached module which will show current URL
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Mar 3, 2020
1 parent 8f79348 commit 44bc4a1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
6 changes: 6 additions & 0 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ class Extension {
}

return next(document, position, context, token);
},
provideCodeLenses: (document, token, next) => {
if (!isInDeno(document.uri.fsPath)) {
return;
}
return next(document, token);
}
}
};
Expand Down
47 changes: 47 additions & 0 deletions server/src/language/code_lens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
IConnection,
Range,
TextDocuments,
Position
} from "vscode-languageserver";
import { TextDocument } from "vscode-languageserver-textdocument";
import { URI } from "vscode-uri";

import { CacheModule } from "../../../core/deno_cache";
import { isInDeno } from "../../../core/deno";

export class CodeLens {
constructor(connection: IConnection, documents: TextDocuments<TextDocument>) {
connection.onCodeLens(params => {
const { textDocument } = params;

const document = documents.get(textDocument.uri);

if (!document) {
return [];
}

const filepath = URI.parse(document.uri).fsPath;

if (!isInDeno(filepath)) {
return [];
}

const cache = CacheModule.create(filepath);

if (!cache) {
return;
}

return [
{
range: Range.create(Position.create(0, 0), Position.create(0, 0)),
command: {
title: `Deno cached module \`${cache.url.href}\``,
command: ""
}
}
];
});
}
}
5 changes: 4 additions & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { DocumentHighlight } from "./language/document_highlight";
import { DocumentFormatting } from "./language/document_formatting";
import { Hover } from "./language/hover";
import { Completion } from "./language/completion";
import { CodeLens } from "./language/code_lens";

import { getDenoDir, getDenoDts } from "../../core/deno";
import { pathExists } from "../../core/util";
Expand All @@ -51,6 +52,7 @@ new DocumentHighlight(connection, documents);
new DocumentFormatting(connection, documents, bridge);
new Hover(connection, documents);
new Completion(connection, documents);
new CodeLens(connection, documents);

connection.onInitialize(
(): InitializeResult => {
Expand All @@ -71,7 +73,8 @@ connection.onInitialize(
documentHighlightProvider: true,
hoverProvider: true,
referencesProvider: true,
definitionProvider: true
definitionProvider: true,
codeLensProvider: {}
}
};
}
Expand Down

0 comments on commit 44bc4a1

Please sign in to comment.