0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CursorでPythonの一部の変数だけ色が付くのが遅かった

0
Last updated at Posted at 2026-06-09

はじめに

CursorでPython開発をしていたところ、補完や定義ジャンプは正常に動作しているにもかかわらず、クラス名や型名だけシンタックスハイライトが効かない現象に遭遇しました。

最初はPython拡張やPyrightの不具合を疑いましたが、最終的には pyproject.toml の設定を見直すことで解決できました。

1. 発生した問題

環境

  • Cursor
  • Python 3.11
  • 仮想環境(venv)
  • 中規模プロジェクト(約80ファイル)

症状

例えば次のコードを開いたとき、

from pathlib import Path

p = Path("sample")

fromimport には色が付くのに、Pathp が灰色のままになっていました。

しかし、

  • 補完は動作する
  • 定義ジャンプできる
  • 型情報も表示される
  • エラー診断も正常

という状態でした。

時間を置くと色が付く

さらに観察すると、問題のプロジェクトでしばらく待つと色が付きました。

2. 解決方法

原因としては、Pyrightの解析対象が広く、
セマンティックトークンの生成に時間がかかっていた可能性が高そうでした。
そこで pyproject.toml を見直し、解析対象を限定しました。

[tool.pyright]
exclude = [
    ".venv",
    "__pycache__",
    "build",
    "dist"
]

pyrightconfig.jsonを編集でもいいらしいです。

pyrightconfig.json
{
  "exclude": [
    ".venv",
    "**/__pycache__",
    "build",
    "dist"
  ]
}

結果

設定変更後は、

  • クラス名
  • 型名
  • 標準ライブラリの型
  • 自作クラス

などに即座に色が付くようになりました。

起動直後に長時間待たされることもなくなり、補完や型解析も快適になりました。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?