Sublime 的 TypeScript 插件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12845412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:15:01  来源:igfitidea点击:

TypeScript plugin for Sublime

sublimetext2typescript

提问by speg

So Microsoft offers syntax highlighting for ST2, but not much else.

所以微软为 ST2 提供了语法高亮,但其他的不多。

How hard would it be to build a plugin that can replicate a lot of the IDE features. I figure if they can replicate it in JS (in the playground) it shouldn't be -THAT- hard to as a ST2 plugin. I'm just not sure where to start... I know how to build a ST2 plugin... but I know nothing about compilers, parsers, etc...

构建一个可以复制许多 IDE 功能的插件有多难。我想如果他们可以在 JS 中(在操场上)复制它,那么作为 ST2 插件应该不会那么难。我只是不确定从哪里开始……我知道如何构建 ST2 插件……但我对编译器、解析器等一无所知……

采纳答案by Vojta

There is new TypeScript Plugin for Sublime Text from Microsoft: https://github.com/Microsoft/TypeScript-Sublime-Plugin

微软为 Sublime Text 提供了新的 TypeScript 插件:https: //github.com/Microsoft/TypeScript-Sublime-Plugin

回答by CodeSalad

[edit]Here's a list of started TS plugins, that I'll try to keep up-to-date:

[编辑]这是已启动的 TS 插件列表,我会尽量保持最新状态:

[/edit]

[/编辑]

We already added basic TypeScript support for SublimeLinter, see this pull request. This will at least show you TypeScript errors in Sublime. It works, but will be slow for big projects as all referenced files will be parsed on every lint. This needs to be fixed in the future.

我们已经为SublimeLinter添加了基本的 TypeScript 支持,请参阅此拉取请求。这至少会显示 Sublime 中的 TypeScript 错误。它可以工作,但对于大型项目来说会很慢,因为所有引用的文件都将在每个 lint 上进行解析。这需要在未来修复。

As TypeScript and its services are written in TypeScript itself, they convert to JS and thus can be used from nodejs and in consequence from Sublime (as Christopher Pappas suggested). This is exactly how the TypeScript support in SublimeLinter works.

由于 TypeScript 及其服务是用 TypeScript 本身编写的,因此它们可以转换为 JS,因此可以从 nodejs 和 Sublime 中使用(正如 Christopher Pappas 建议的那样)。这正是 SublimeLinter 中 TypeScript 支持的工作原理。

If you want to create a full-featured Sublime plugin, I advice you to take a look at the TypeScript serviceswhich provide all the necessary functions for auto-completion and such. languageService.tsshould be what you are looking for. Also, you should take a look at the source-code of the TypeScript Playground, as they provide auto-completion through JS on the web. Unfortunately you have to un-minify the source yourself, as there is no offical source-code for playground.

如果你想创建一个全功能的 Sublime 插件,我建议你看看 TypeScript服务,它提供了自动完成等所有必要的功能。languageService.ts应该是你要找的。此外,您应该查看 TypeScript Playground的源代码,因为它们通过网络上的 JS 提供自动完成功能。不幸的是,您必须自己取消缩小源代码,因为 Playground 没有官方源代码。

In any case, I would be gladly willing to help if you are really interested in creating a Sublime TypeScript plugin!

无论如何,如果您真的对创建 Sublime TypeScript 插件感兴趣,我很乐意提供帮助!

[edit]

[编辑]

You should also look at the Sublime documentation for information about adding completions.

您还应该查看 Sublime 文档以获取有关添加完成的信息。

回答by cnp

I would have a look at these other possiblesolutions, particular to Node, and go from there:

我会看看这些其他可能的解决方案,特别是 Node,然后从那里开始:

Use TypeScript compiler from node

从节点使用 TypeScript 编译器

Does TypeScript provide an explicit Public API for NodeJS Module Access?

TypeScript 是否为 NodeJS 模块访问提供了明确的公共 API?

回答by karthick nagarajan

TypeScript Plugin for Sublime Text

用于 Sublime 文本的 TypeScript 插件

  • Select

    Preferences --> Setting - User 
    
  • Add this line

    "typescript_tsdk": "<path to your folder>/node_modules/typescript/lib"
    
  • Mac And Ubuntu:

    cd ~/"Library/Application Support/Sublime Text 3/Packages"

    git clone --depth 1 https://github.com/Microsoft/TypeScript-Sublime-Plugin.git TypeScript
    
  • And on Windows:

    cd "%APPDATA%\Sublime Text 3\Packages"

    git clone --depth 1 https://github.com/Microsoft/TypeScript-Sublime-Plugin.git TypeScript
    
  • 选择

    Preferences --> Setting - User 
    
  • 添加这一行

    "typescript_tsdk": "<path to your folder>/node_modules/typescript/lib"
    
  • Mac 和 Ubuntu:

    cd ~/"库/应用程序支持/Sublime Text 3/包"

    git clone --depth 1 https://github.com/Microsoft/TypeScript-Sublime-Plugin.git TypeScript
    
  • 在 Windows 上:

    cd "%APPDATA%\Sublime Text 3\Packages"

    git clone --depth 1 https://github.com/Microsoft/TypeScript-Sublime-Plugin.git TypeScript
    

回答by cancerbero

TypeScript is more than just a language and compiler. It provides with a server which can be extensible through third party plugins. We as users an design and implement our own extensions such as:

TypeScript 不仅仅是一种语言和编译器。它提供了一个可以通过第三方插件扩展的服务器。我们作为用户设计并实现我们自己的扩展,例如:

  • refactor suggestions
  • autocompletion
  • file / module custom resolution
  • compiler diagnostics
  • etc, etc
  • 重构建议
  • 自动完成
  • 文件/模块自定义分辨率
  • 编译器诊断
  • 等等等等

And the good part is that if you implement your solution using this infrastructure every major editor will support it out of the box:) I know that at least vscode, atom webstorm and sublime have plugins that just communicate with tsserver (TypeScript Language server) and consume all the functionality it provides.

好的部分是,如果您使用此基础架构实现您的解决方案,每个主要编辑器都会开箱即用:) 我知道至少 vscode、atom webstorm 和 sublime 有只与 tsserver(TypeScript 语言服务器)通信的插件和使用它提供的所有功能。

I just entered this fantastic world, but unfortunately documentation is poor nevertheless I had some progress. If you are goind to start with this these are my recommendations:

我刚进入这个奇妙的世界,但不幸的是文档很差,但我取得了一些进展。如果您打算从这里开始,这些是我的建议:

Start here:

从这里开始:

This is my collection of small plugins (I'm just getting started so is WIP) https://github.com/cancerberoSgx/typescript-plugins-of-mineIn particular I recommend you to start with the tutorial: https://cancerberosgx.github.io/typescript-plugins-of-mine/sample-ts-plugin1/src/

这是我的小插件集合(我刚刚开始,WIP 也是如此)https://github.com/cancerberoSgx/typescript-plugins-of-mine特别是我建议您从教程开始:https:// cancerberosgx.github.io/typescript-plugins-of-mine/sample-ts-plugin1/src/

Feedback is most welcome, thanks!

非常欢迎反馈,谢谢!

回答by aefxx

May I suggest you have a look into Let's build a compileror the wounderful book Language Implementation Patternsif you need a thorough reference on best practice algorithms.

如果您需要有关最佳实践算法的全面参考,我建议您看看Let's build a compiler或伤人的书籍Language Implementation Patterns