-
Notifications
You must be signed in to change notification settings - Fork 237
Dev notes
Daniel Rosenwasser edited this page Jul 1, 2015
·
6 revisions
In order to be able to install the TypeScript
package from Package Control, and also develop
and test with a locally installed plug-in, you can add the local enlistment as a plug-in with a
different name (here I use TypeScriptLang
), and then disable one or the other via settings.
For example, to clone the repo locally and then add it as the TypeScriptLang
plugin, use the below:
cd C:\src
git clone https://github.com/Microsoft/TypeScript-Sublime-Plugin.git
MKLINK /J "%APPDATA%\Sublime Text 2\Packages\TypeScriptLang" "C:\src\TypeScript-Sublime-Plugin"
MKLINK /J "%APPDATA%\Sublime Text 3\Packages\TypeScriptLang" "C:\src\TypeScript-Sublime-Plugin"
cd ~/src
git clone https://github.com/Microsoft/TypeScript-Sublime-Plugin.git
ln -s ~/"src/TypeScript-Sublime-Plugin" ~/"Library/Application Support/Sublime Text 3/Packages/TypeScriptLang"
ln -s ~/"src/TypeScript-Sublime-Plugin" ~/"Library/Application Support/Sublime Text 2/Packages/TypeScriptLang"
cd ~/src
git clone https://github.com/Microsoft/TypeScript-Sublime-Plugin.git
ln -s ~/src/TypeScript-Sublime-Plugin ~/.config/sublime-text-2/Packages
ln -s ~/src/TypeScript-Sublime-Plugin ~/.config/sublime-text-3/Packages
*Note: This puts the repo under a `src` folder and uses file system links to add it to the
plugin folder. Skip the ST2 or ST3 path addition if you don't have that version installed.*
To disable the Package Control `TypeScript` plugin while you work with the local copy, open
the `Settings - User` file from Preferences, and add `"TypeScript"` to the `"ignored_packages"`
property. If it already contained `"Vintage"` (which it does by default), it should now appear as:
"ignored_packages": [ "Vintage", "TypeScript" ],
If/when you want to switch back to using the Package Control installed `TypeScript` plugin and
disable the local dev plugin, replace the `"TypeScript"` string above with the name of the local
plugin copy (e.g. `"TypeScriptLang"` above).
## Coding style
In general, code should aim to align with the Python coding guidelines outlined in PEP8
(https://www.python.org/dev/peps/pep-0008/).
If writing Python code in Sublime Text 3,
then the excellent `Anaconda` package (https://github.com/DamnWidget/anaconda) can be installed
via Package Control, and provides linting and error highlighting for code that does not conform.
## Debugging
Liberal logging using the [logger](https://github.com/Microsoft/TypeScript-Sublime-Plugin/blob/master/libs/logger.py) module provided under the ./libs directory is
often the fastest way to narrow down a problem. See usage throughout the code
for example of this. By default this writes logging calls to a `TS.log` file in the
plugin folder. The logging level can be set in the first few lines of TypeScript.py. The `log`
object exposed from the module is a Python `logger` object from the standard [logging](https://docs.python.org/2.6/library/logging.html) module.
As well as writing to the log file, output is also sent to the Sublime Console. Any exceptions
that occur also appear in the Sublime Console, and this is a good place to start investigating.
For the Node process that runs the server, logging may be enabled by setting the TSS_LOG
environment variable. Set to `-level verbose` to enable verbose logging (for example, on OS X,
from the Terminal run `export TSS_LOG="-level verbose"` before launching Sublime from the same
terminal session). Search on `TSS_LOG` in `./tsserver/tsserver.js` for more details on valid values.
If logging doesn't help, there are a couple of tools that can be used to provide an interactive
debugging experience.
### Visual Studio
To debug in the Visual Studio Tools for Python see
http://pytools.codeplex.com/wikipage?title=Features%20Remote%20Debugging . Copy
the `ptvsd` directory/package outlined to the `./libs` directory. The code already
exists in the `TypeScript.py` file to try to load this module. Now from within VS,
attach to `tcp://127.0.0.1/` via the Python Remote Debugging transport.
### PDB
To debug using the Python command-line debugger, the standard `pdb` module is
insufficient, as stdin/stdout is not accessible in a plugin context. You can
expose `pdb` over a TCP socket via the `rpdb` module. Clone this from
https://github.com/tamentis/rpdb, copy the `rpdb` folder into the `./libs`
folder so that `import rpdb` works, i.e.:
cd ~/src git clone https://github.com/tamentis/rpdb cp -R ~/src/rpdb/rpdb/ ~/"src/TypeScript-Sublime-Plugin/lib/rpdb"
After importing `rpdb`, calling `rpdb.set_trace()` triggers a breakpoint. You may
`telnet 127.0.0.1 4444` to access the command line debugger functionality
exposed by `pdb`. See https://docs.python.org/3/library/pdb.html for usage.