Skip to content
This repository has been archived by the owner on Jul 17, 2022. It is now read-only.

Feature Request: Support Deno LSP #2

Closed
David-Else opened this issue Mar 26, 2021 · 6 comments
Closed

Feature Request: Support Deno LSP #2

David-Else opened this issue Mar 26, 2021 · 6 comments

Comments

@David-Else
Copy link

David-Else commented Mar 26, 2021

Deno has the fastest TypeScript LSP and is fully supported in nvim-lspconfig https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#denols

Deno LSP is a work in progress, here is the current state: denoland/deno#8643

There are some limitations when using it with Web based code, but I have found that combined with https://github.com/evanw/esbuild you can get fantastic results. You need to make all imports deno compatible by using the .ts extension, but esbuild accepts that and bundles to js without problem.

To use DOM based code add /// <reference lib="dom" /> to each file.

If you want to have a go, this will scaffold it for you:

#!/bin/bash

hash "deno" 2>/dev/null || {
    echo >&2 "You need to install deno from https://deno.land/manual/getting_started/installation"
}

hash "live-server" 2>/dev/null || {
    echo >&2 "You need to install live-server https://www.npmjs.com/package/live-server"
}

mkdir dist src test assets
# touch src/{main.css,index.html}

cat >"dist/index.html" <<'EOL'
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>App</title>
  </head>
  <body>
    <script type="module" src="bundle.js"></script>
  </body>
</html>
EOL

cat >"bundle.sh" <<'EOL'
#!/bin/bash

clear
npx esbuild --watch --bundle --minify --sourcemap --format=esm src/mod.ts --outfile=dist/bundle.js &
npx live-server ./dist &
wait
EOL
chmod +x bundle.sh

cat >"test.sh" <<'EOL'
#!/bin/bash

clear
deno test --allow-all test/
EOL
chmod +x test.sh

cat >".gitignore" <<'EOL'
dist
EOL

cat >"src/mod.ts" <<'EOL'
/// <reference no-default-lib="true"/>
/// <reference lib="dom" />  
/// <reference lib="deno.ns" />
/// <reference lib="esnext" />        

/**
 * @file Application entry point
 */

export function example(): number {
  return 42;
}
EOL

cat >"deps.ts" <<'EOL'
export {
  assert,
  assertEquals,
  assertStrictEquals,
} from "https://deno.land/[email protected]/testing/asserts.ts";
EOL

cat >"test/mod_test.ts" <<'EOL'
import { assertEquals } from "../deps.ts";
import { example } from "../src/mod.ts";

Deno.test({
  name: "example test",
  fn(): void {
    // Arrange
    const expectedResult = 42;
    // Act
    const result = example();
    // Assert
    assertEquals(result, expectedResult);
  },
});
EOL

npm install
git init
echo "Template Generated!"
@jose-elias-alvarez
Copy link
Owner

Interesting. I've never used Deno, but it looks like the language server supports the features required to handle the plugin's current functions. I'll look into it (I've wanted an excuse to give Deno a shot, anyways) and see if it's possible.

@David-Else
Copy link
Author

@jose-elias-alvarez Did you get a chance to have a look at Deno? It would be amazing if this plugin was compatible. There have been a lot of updates in the last two months to the LSP.

@jose-elias-alvarez
Copy link
Owner

I haven't, though I am still (personally) very interested in it. Is there a good source for Deno LSP documentation re: features and implementation? I was able to find this issue, but I'm not sure if it's definitive, and I don't know Rust, so parsing the code isn't easy for me.

@David-Else
Copy link
Author

The rust module has documentation about the implementation: https://github.com/denoland/deno/tree/main/cli/lsp#custom-requests . Some of these custom requests are available in Neovim:

https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#denols

  Commands:
  - DenolsCache: Cache a module and all of its dependencies.
  - DenolsDefinition: Jump to definition. This handle deno:/ schema in deno:// buffer.
  - DenolsReferences: List references. This handle deno:/ schema in deno:// buffer.

Afraid I know nothing about LSP's really and can't be of much help :(

I think your best bet might be look at the official VS Code plugin https://github.com/denoland/vscode_deno which is written in TypeScript. Also, I am certain that more knowledgeable people would love to answer any of your questions on the discord channel https://discord.com/invite/deno or the Github discussion channel https://github.com/denoland/deno/discussions

There is general editor LSP integration stuff at https://deno.land/manual/getting_started/setup_your_environment#editors-and-ides , not much use, but you could look at how other IDE's are doing it other than the official plugin.

@jose-elias-alvarez
Copy link
Owner

Awesome, thanks for the info. A good chunk of the complexity in this plugin is getting offloaded to another plugin, so I think there might be room to include Deno support if it's a possibility. I'll investigate and let you know.

@jose-elias-alvarez
Copy link
Owner

So I've started playing around with Deno myself a bit, but as I mentioned in #87, in the future I'd like to turn this plugin into a "full-featured" language server plugin that takes care of setting up tsserver, passing down / modifying options, and handling off-spec behavior. This is mentioned in the lspconfig roadmap, and I'm waiting for the lspconfig maintainers to publish guidelines so that we can start moving in that direction.

With that in mind, I think Deno support would be out-of-scope for this plugin, so I'm going to close this issue. As I understand it, the Deno language server is more compliant with the LSP protocol and doesn't have to deal with the weirdness of a wrapper like typescript-language-server, so I think a lot of the current functionality wouldn't apply, anyways.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants