Skip to content

Instantly share code, notes, and snippets.

Forked from davethesoftwaredev/TypeScript.plist
Last active November 18, 2022 21:41
  • Star 16 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
BBEdit Codeless Language Module for TypeScript syntax coloring and class/interface/function folding.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
BBEdit Language Module for TypeScript
Put this file in
~/Library/Application Support/BBEdit/Language Modules
or equivalent.
Forked from
Which in turn were based on the language file for CoffeeScript found at
See also
<plist version="1.0">
<key>Language Features</key>
<key>Identifier and Keyword Character Class</key>
<key>Comment Pattern</key>
(?> (?<!\\) // .* $ ) |
(?> /\* (?s:.*?) (?> \*/ | \z ) )
<key>Function Pattern</key>
(?P<leadspace>^[ \t]*)
<key>String Pattern</key>
(?> " [^"\r]* ") |
(?> ' [^'\r]* ') |
(?> ` [^`]* `)
<key>Skip Pattern</key>
(?P>comment) |
Copy link

isao commented Sep 17, 2014

To paraphrase the docs, the function pattern is simplified by the forlorn assumption that the end brace will be indented by the same amount of leading space before the definition.

Copy link

isao commented Dec 3, 2015

updated for ts 1.7 and bbedit 11.5 beta

Copy link

isao commented Apr 7, 2017

This was getting slow on some very large TypeScript files, and I realized the string pattern could be simplified...

Copy link

jtlapp commented Oct 27, 2017

When installed, BBedit gets very slow entering text in files of extension '.ts'. For example, enter this:

function someVeryLongFunctionName() { }

function anotherVeryLongFunctionName() { }

function stillAnotherVeryLongFunctionName() { }

The more times you duplicate this line, the slower typing gets. Try about 500.

Duplicate that comment line many times. Then try typing within the file. It takes about two seconds to insert each character.

I did quite a bit of experimenting to reduce my code to the above clip. I had a few hundred lines of code and only a few end-of-line comments sprinkled about. Replace that long comment with lots of code, and you get the same effect.

The effect vanishes when you greatly shorten the function names. The longer the function name, the longer character insertion takes. The more long function names you have, the longer and longer it takes to insert a character. I tend to be pretty descriptive with my function names, so my Typescript files are slowing to a crawl.

I haven't tried experimenting with other sort of identifiers to see if they produce the same effect.

Copy link

jtlapp commented Oct 27, 2017

The problem occurs regardless of whether the closing braces are on their own lines, regardless of whether the functions contain code. I played with fixing it but don't grok the syntax well enough.

Copy link

isao commented Nov 8, 2017

@jtlapp: interesting, I wonder if that's because of the alternation in the comment regex: (?> /\* (?s:.*?) (?: \*/ | \z ) )

If you don't mind not matching the "or end of file" condition, you can remove the | \z part.

update: didn't seem to help.

Copy link

isao commented Feb 6, 2018

I replaced some (?: with (?>, and tweaked the function pattern. Perf issue seems to have gone away, perhaps because of v12.1 update to 64 bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment