Skip to content

Conversation

@hinerm
Copy link

@hinerm hinerm commented Aug 23, 2025

The main fix that was breaking Omega on mac was the hard-coded preferred model list generation failing. This was resolved by moving to a black/white list of models that we only update if the models actually exist.

The syntax highlighting fix improved my experience but is only tested on mac and may need to be platform-dependent

Finally, high DPI scaling has to be done earlier before GUI initialization.

Summary by CodeRabbit

  • New Features

    • Enabled High-DPI display support for sharper, clearer UI on supported systems.
    • Enhanced model selection: preferred options appear first and unsupported models are hidden.
  • Bug Fixes

    • Improved Python syntax highlighting by correcting regex escape handling to prevent mis-highlighting and warnings.
  • Refactor

    • Centralized display scaling logic to streamline startup behavior.

hinerm added 4 commits August 14, 2025 07:25
This makes future updates simpler.

Also I believe the blacklist should be removed from models itself, not
"preferred_models", as we created preferred_models.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 23, 2025

Walkthrough

Updates model selection logic to use whitelist/blacklist with stable preferred-first sorting, adds High DPI attributes in the main widget startup, removes redundant DPI setup from the code editor window, and converts regex patterns in the syntax highlighter to raw strings without changing behavior.

Changes

Cohort / File(s) Summary of changes
Model selection & DPI init
src/napari_chatgpt/_widget.py
Switched to whitelist/blacklist model handling; removed blacklisted entries; built preferred list via substring matches; stable-sorted to place preferred models first. Added PyQt5 High DPI attributes (AA_UseHighDpiPixmaps, AA_EnableHighDpiScaling) before QApplication creation.
Code editor window init
src/napari_chatgpt/microplugin/code_editor/code_snippet_editor_window.py
Removed High DPI Qt attribute setup; no other functional changes.
Syntax highlighting regex literals
src/napari_chatgpt/microplugin/code_editor/python_syntax_highlighting.py
Converted escaped regex strings to raw strings for operator and brace tokens; no control-flow changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant M as main()
  participant Qt as Qt Application
  participant W as Widget init
  participant ML as Model list builder

  U->>M: Launch application
  activate M
  M->>Qt: Set AA_UseHighDpiPixmaps (if available)
  M->>Qt: Set AA_EnableHighDpiScaling (if available)
  M->>Qt: Create QApplication
  deactivate M

  M->>W: Initialize widget
  activate W
  W->>ML: Prepare model_list
  note over ML: Start with available models
  ML->>ML: Remove blacklist entries
  ML->>ML: Identify preferred via whitelist substrings
  ML->>ML: Stable sort: preferred first
  ML-->>W: Return ordered list
  W-->>U: Populate UI with models
  deactivate W
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

A whisk of code, a hop so spry,
Models sorted, ranked up high.
DPI dreams now crisp and clear,
Regex strings without a fear.
I twitch my nose, compile, then sigh—
Another carrot merged, oh my! 🥕

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/napari_chatgpt/_widget.py (3)

165-168: Whitelist/blacklist approach: OK; minor nit and future-proofing suggestion

The switch to explicit allow/deny lists fixes the macOS breakage risk. Two small nits:

  • The method name is misspelled (_prefered_models). Consider renaming to _preferred_models for clarity (low priority since it's private).
  • Consider hoisting whitelist/blacklist to module-level constants so they’re easier to audit and tweak.

169-173: Make “preferred-first” ordering truly stable and speed up membership checks

Current sort key (x not in preferred_models, x) re-sorts each group lexicographically, which is not stable relative to the incoming order. Also, membership checks against a list are O(n). Use a set and rely on Python’s stable sort with a single boolean key.

Apply this diff:

-        # Add models containing any whitelist string
-        preferred_models = [
-            model for model in model_list if any(w in model for w in whitelist)
-        ]
+        # Add models containing any whitelist string
+        preferred_set = {
+            model for model in model_list if any(w in model for w in whitelist)
+        }
@@
-        # Sort the model list stably to have preferred models first:
-        model_list.sort(key=lambda x: (x not in preferred_models, x))
+        # Stable sort: keep original order within groups, preferred first
+        model_list.sort(key=lambda x: x not in preferred_set)

Please verify the visual ordering in the dropdown matches prior expectations when the upstream model enumeration order changes (e.g., add/remove a model at runtime).

Also applies to: 181-183


174-180: Replace try/except/pass with contextlib.suppress for cleaner intent

Silence-only exception handling is clearer with suppress and satisfies static analysis (SIM105).

Apply this diff:

-        for b in blacklist:
-            try:
-                model_list.remove(b)
-            except ValueError:
-                pass
+        for b in blacklist:
+            with suppress(ValueError):
+                model_list.remove(b)

And add the import (outside this hunk):

+from contextlib import suppress
src/napari_chatgpt/microplugin/code_editor/python_syntax_highlighting.py (1)

87-109: Raw string regexes for operators: good; consider adding missing Python 3 operators

The conversion to raw strings removes double-escaping pitfalls. As a nice-to-have, include additional Python 3 operators for completeness:

  • Walrus operator := and its in-place variant doesn’t exist, but include :=.
  • Matrix multiply @ and @=.

Example patch:

         # In-place
         r"\+=",
         "-=",
         r"\*=",
         "/=",
         r"\%=",
+        # Assignment expression and matrix multiply
+        r":=",
+        r"@",
+        r"@=",
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8275381 and 6cc693d.

📒 Files selected for processing (3)
  • src/napari_chatgpt/_widget.py (2 hunks)
  • src/napari_chatgpt/microplugin/code_editor/code_snippet_editor_window.py (0 hunks)
  • src/napari_chatgpt/microplugin/code_editor/python_syntax_highlighting.py (1 hunks)
💤 Files with no reviewable changes (1)
  • src/napari_chatgpt/microplugin/code_editor/code_snippet_editor_window.py
🧰 Additional context used
🧬 Code graph analysis (1)
src/napari_chatgpt/_widget.py (1)
src/napari_chatgpt/utils/openai/model_list.py (2)
  • postprocess_openai_model_list (83-149)
  • get_openai_model_list (8-80)
🪛 Ruff (0.12.2)
src/napari_chatgpt/_widget.py

176-179: Use contextlib.suppress(ValueError) instead of try-except-pass

Replace with contextlib.suppress(ValueError)

(SIM105)

🔇 Additional comments (2)
src/napari_chatgpt/_widget.py (1)

571-575: High-DPI attributes set before QApplication creation — good move

Setting AA_UseHighDpiPixmaps and AA_EnableHighDpiScaling before instantiating QApplication is correct and should prevent blurry rendering on macOS Retina displays.

src/napari_chatgpt/microplugin/code_editor/python_syntax_highlighting.py (1)

113-119: Raw string regexes for braces — LGTM

Escaping braces/parens/brackets with raw strings is correct and clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant