microsoft / TypeScript-Sublime-Plugin

IO wrapper around TypeScript language services, allowing for easy consumption by editor plugins
Apache License 2.0
1.72k stars 235 forks source link

How to disable typescript plugin or typescript server for vue(lang="ts") file? #665

Closed django-wong closed 5 years ago

django-wong commented 6 years ago

I can disable typescript plugin globally but I still want this plugin enabled for my other pure typescript project or file

screen shot 2018-05-18 at 11 22 15 am
muweigg commented 6 years ago

+1 >_<

django-wong commented 6 years ago

Try this

Alter file typescript/libs/view_helpers.py to update function is_typescript like this:

def is_typescript(view):
    """Test if the outer syntactic scope is 'source.ts' or 'source.tsx' """
    filename = view.file_name()
    blocklist = [".vue", ".html"]
    name, extension = os.path.splitext(filename)
    if not filename:
        return False

    if extension in blocklist:
        return False

    try:
        location = view.sel()[0].begin()
    except:
        return False

    return (view.match_selector(location, 'source.ts') or
            view.match_selector(location, 'source.tsx'))

Do not forget import os

muweigg commented 6 years ago

@django-wong Good job, It works fine, thank you.

nehbit commented 6 years ago

Thanks @django-wong. This saved my bacon as well, I was on the verge of giving up and stop using Typescript for new Vue files from now on.

One tip: doing it this way will also remove the typescript syntax highlighting and lint-on-save from your vue files as well, since Microsoft's implementation is a monolith, all or nothing. You can't easily get back lint-on-save in vue files, but you can get back syntax highlighting by installing the Typescript Syntax for Sublime text, which as far as I can see is just a copy of this plugin's syntax higlighting exported into its own extension.

django-wong commented 6 years ago

@nehbit that's true, also use LSP + vue-language-server can bring the code intellisence back

DanielRosenwasser commented 5 years ago

Sorry for the delay, the fix is out at #705.

nehbit commented 5 years ago

Thank you!