Sublime Forum

[SublimeLinter] How do I know what language the source is?


Sorry if this is the wrong place for asking SublimeLinter questions; I don’t see a dedicated forum for it. Please point me in the right direction if I’m in the wrong spot.

I’m writing a linter plugin that’s going to be an experiment in supporting multiple languages using a common linting engine (written in Python). I’d like to be able to do this with a single plugin rather than writing multiple plugins, and I’d like to do all of the linting internally. It’s a crazy idea, I know, but I’m going to try it anyway.

I’m looking at the docs and the examples, and even the SL source code, and I’m not seeing where SL tells the plugin what language the text-to-be-linted is. I know that ST has some magic for language detection, and I assumed that SL would pass that on to its plugins. Was that a bad assumption?

If I can’t get the language info from SL, can I put multiple Linter sublclasses in the same plugin? If that works then maybe I can write a script that autogenerates Linter subclasses for each language.



Because it’s your responsibility to tell SL.

The most important setting is  `"selector"` , which specifies the scopes for which the linter is run.


Thanks. I did see that, and it makes sense for a single-syntax linter, but…

The quoted bit of documentation implies that multiple scopes can be specified in “selector”. If my plugin specifies more than one scope, how do I know which scope is “active” on any particular invocation of the run() method?



I am afraid that it’s just not the design goal of SL in your case. I.e., SL is not designed to make a plugin for all languages.

Using ST’s API scope_name(point) to get the scope at a certain point? I don’t know… since I feel this way is off the track of SL plugin.

The author @braver of SL itself is in the Discord chat channel. Maybe he/she can provide a more decent suggestion quicker there. (he/she is not online now)



Scopes work like css selectors, you can have multiple by specifying a comma separated list. I’m not 100% sure, but if you set it to a single space ” “ I think your linter should run on all files. You can have a look a the TODO linter, which has a similar goal:

If you have questions you can open an issue in the main repo, that usually gets our attention.

1 Like


Thanks. I created Issue #1628.