speg
speg

Reputation: 2019

TypeScript plugin for Sublime

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

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...

Upvotes: 10

Views: 20609

Answers (6)

cancerbero
cancerbero

Reputation: 7045

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:

  • 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.

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-mine In particular I recommend you to start with the tutorial: https://cancerberosgx.github.io/typescript-plugins-of-mine/sample-ts-plugin1/src/

Feedback is most welcome, thanks!

Upvotes: 0

Karthick Nagarajan
Karthick Nagarajan

Reputation: 1345

TypeScript Plugin for Sublime Text

  • 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
    

Upvotes: 1

Vojta
Vojta

Reputation: 1623

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

Upvotes: 7

CodeSalad
CodeSalad

Reputation: 1375

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

[/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.

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.

If you want to create a full-featured Sublime plugin, I advice you to take a look at the TypeScript services which provide all the necessary functions for auto-completion and such. languageService.ts should 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.

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

[edit]

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

Upvotes: 12

cnp
cnp

Reputation: 1028

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

Use TypeScript compiler from node

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

Upvotes: 2

aefxx
aefxx

Reputation: 25279

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

Upvotes: -3

Related Questions