4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ATOM1.24で最新のPythonシンタックスハイライトを使用する

Last updated at Posted at 2018-02-22

概要

2018年02月安定版のATOM(1.24)上でPython3のType hints機能を使用するとハイライトが上手く機能しなくなります。
スクリーンショット 2018-02-22 12.36.49.png
理由としてはATOM(1.24)に同梱されているlanguage-python(0.45.6)がType hintsを考慮していないからです。

サポート状況

最新の*language-python(0.49.2)*はType hintsをサポートしています.(PR:#234

そのため以下の方法で解決することができます

  • ATOM1.25のベータ版を使用する(追記: 2018年05月現在安定版が存在します)
  • ATOM1.24に最新のlanguage-pythonを入れる

今回は後者の方法で対応することにしました。

buildin-packageアップデート出来ない問題

language-pythonはATOMに最初から同梱されているパッケージなのですが、
apmでアップデートしようとすると警告がでてきます。

% apm install language-python
The language-python package is bundled with Atom and should not be explicitly installed.
You can run `apm uninstall language-python` to uninstall it and then the version bundled
with Atom will be used.
Installing language-python to /Users/user/.atom/packages ✓

ただ、アップデートが出来ないだけで、apmの管理ディレクトリにインストールされます。
※ buildinと最新の二つがATOMにインストールされた状態になる。

パッケージ名被る問題

このまま利用開始しようとすると0.45.6と0.49.2が競合して動かないので古い方を無効化したいのですが
バージョン単位で無効化する機能がATOMにないので上手く行きませんでした.
buildinのパッケージを削除してやろうと思ったのですがどこにあるかわかりませんでした。

そこでパッケージ名を変更することにしました。以下の方法で変更できます。

% cd ~/.atom/packages
% mv language-python language-python-latest

その後language-pythonを無効化、language-python-latestを有効化します。

1.25向けのパッケージを1.24向けにする対応

1.25では言語名の管理方法が変更されているようなので以下のファイルを修正します
language-python-latest/grammars/tree-sitter-python.cson

id: 'python'
name: 'Python'
type: 'tree-sitter'
parser: 'tree-sitter-python'
legacyScopeName: 'source.python'

id: 'python'
# name: 'Python'
type: 'tree-sitter'
parser: 'tree-sitter-python'
legacyScopeName: 'source.python'
scopeName: 'source.python'

うまくいきました
スクリーンショット 2018-02-22 12.53.06.png

上手く表示されない場合はファイルを閉じて再度開くとうまくいきます(古いlanguage-pythonが選択されている状態になっている)。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?