Sublime Forum

View.assign_syntax do not accept Syntax object

#1

From documentation:

assign_syntax(syntax)
Changes the syntax used by the view. syntax may be a Syntax object, packages path to a syntax file, or scope: specifier string.

But

>>> view.assign_syntax(sublime.find_syntax_by_name('JSON'))
Traceback (most recent call last):
  File "__main__", line 1, in <module>
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python38/sublime.py", line 1630, in assign_syntax
    sublime_api.view_assign_syntax(self.view_id, syntax)
TypeError: String required
>>> view.assign_syntax(sublime.find_syntax_by_name('JSON')[0])

Did I miss something?

0 Likes

#2

sublime.find_syntax_by_name() returns List[Syntax].

I would suggest you use https://github.com/sublimelsp/LSP-pyright (with ST dev setup) or https://github.com/jfcherng-sublime/ST-API-stubs (for static analysis).


It’s been a while since we’ve seen nilcolor — their last post was 10y ago.

:astonished:

0 Likes

#3

You are right :blush: Not sure why [Syntax] was not seen by myself. Thanks you!

:man_shrugging:

0 Likes