Skip to content

Add extension menu items#21

Merged
cyanzhong merged 9 commits into
mainfrom
copilot/add-proofreading-menu-item
Mar 14, 2026
Merged

Add extension menu items#21
cyanzhong merged 9 commits into
mainfrom
copilot/add-proofreading-menu-item

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 14, 2026

Registers menu entries under a parent "Proofread" submenu with an SF Symbol icon, mirroring the pattern from MarkEdit-preview.

  • src/const.ts — Shared constants; exports the repoUrl for the GitHub repository.
  • src/menu.ts — New module with buildMenuItem(). Creates a parent "Proofread" menu item (icon: 'text.badge.checkmark') with children: "Proofread Now" (re-runs Harper via lint() and dispatches results), "Ignore All" (clears diagnostics), separator, version item, and GitHub releases link.
  • vite.config.mts — Injects __PKG_VERSION__ from package.json at build time via define.
  • types/globals.d.ts — Type declaration for the __PKG_VERSION__ global.
  • main.ts — Calls MarkEdit.addMainMenuItem(buildMenuItem()) directly after extension registration.
  • tests/menu.test.ts — Validates menu structure (parent title, icon, children count, titles, separator, action types).
// main.ts
MarkEdit.addMainMenuItem(buildMenuItem());
// → Proofread (text.badge.checkmark)
//     ├─ Proofread Now
//     ├─ Ignore All
//     ├─ ───
//     ├─ Version 1.0.0
//     └─ Check Release (GitHub)
Original prompt

This section details on the original issue you should resolve

<issue_title>Extension menu item</issue_title>
<issue_description>## Goals

Provide UI menu entries for the proofreading extension using the MarkEdit extension API. The implementation should follow the API contract defined in the MarkEdit API and mirror the pattern used by the preview extension.

Reference implementations:

Menu Hierarchy

Add the following entries to the extension menu:

Implementation Notes

  • Follow conventions used in the MarkEdit preview extension for menu registration and command wiring.
  • Keep menu labels concise and consistent with existing MarkEdit extensions.
  • Ensure menu actions are stateless and safe to invoke repeatedly.
  • The version entry should be informational only and not interactive.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…elease

Co-authored-by: cyanzhong <6745066+cyanzhong@users.noreply.github.com>
Copilot AI changed the title [WIP] Add extension menu items for proofreading Add extension menu items Mar 14, 2026
Copilot AI requested a review from cyanzhong March 14, 2026 09:47
Comment thread types/globals.d.ts
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot Move this to types instead of src.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved to types/globals.d.ts in bb42c7c.

Co-authored-by: cyanzhong <6745066+cyanzhong@users.noreply.github.com>
Copilot AI requested a review from cyanzhong March 14, 2026 09:49
Comment thread src/menu.ts Outdated

const repoUrl = 'https://github.com/MarkEdit-app/MarkEdit-proofreading';

export function buildMenuItems(): MenuItem[] {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot The menu hierarchy is wrong. It should be under a "Proofread" menu (leverage children).

Also, add icon to the "Proofread" menu, it's a sf symbol.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Restructured as a parent "Proofread" menu with children and added icon: 'text.badge.checkmark' in a1867a3.

Co-authored-by: cyanzhong <6745066+cyanzhong@users.noreply.github.com>
Copilot AI requested a review from cyanzhong March 14, 2026 09:56
Comment thread src/menu.ts Outdated
import { setDiagnosticsEffect, lintToDiagnostic } from './decoration';
import { lint } from './lint';

const repoUrl = 'https://github.com/MarkEdit-app/MarkEdit-proofreading';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot move to const.ts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved repoUrl to src/const.ts in 992eccd.

Comment thread src/menu.ts Outdated
};
}

export function addMenuItems() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot this is not needed, since buildMenuItem is already export, move it to main.ts.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed addMenuItems() and moved the MarkEdit.addMainMenuItem(buildMenuItem()) call directly into main.ts in 992eccd.

…Item directly in main.ts

Co-authored-by: cyanzhong <6745066+cyanzhong@users.noreply.github.com>
Copilot AI requested a review from cyanzhong March 14, 2026 10:06
Comment thread src/menu.ts Outdated
const text = doc.sliceString(0);
const lints = await lint(text);

if (view.state.doc !== doc) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot What are you doing here? Is this really a needed pattern??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the stale document check in 70b343d. The lintScheduler in extension.ts already handles auto-refresh on doc changes, so this guard isn't needed for a manual user action.

Copilot AI and others added 2 commits March 14, 2026 10:24
Co-authored-by: cyanzhong <6745066+cyanzhong@users.noreply.github.com>
Co-authored-by: cyanzhong <6745066+cyanzhong@users.noreply.github.com>
Comment thread src/menu.ts Outdated

async function proofreadNow() {
const view = MarkEdit.editorView;
const text = view.state.doc.sliceString(0);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot So you have two sliceString(0) in this codebase, this makes me doubt your skills.

These could have been just .toString(), why not use this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Replaced both sliceString(0) calls with .toString() in menu.ts and extension.ts in b9de631.

Copilot AI requested a review from cyanzhong March 14, 2026 10:27
Co-authored-by: cyanzhong <6745066+cyanzhong@users.noreply.github.com>
@cyanzhong
Copy link
Copy Markdown
Contributor

@copilot Do final self-review.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 14, 2026

@copilot Do final self-review.

Final self-review complete on b9de631.

  • npm test: passed (4 files, 11 tests)
  • npm run build: lint + tests passed; Vite bundle built, then failed only at markedit-vite post-build copy step because /home/runner/Library/Containers/app.cyan.markedit/... does not exist in this sandbox
  • code_review: no changed files to review
  • codeql_checker: no analyzable code changes detected

No additional code changes are needed from this self-review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a “Proofread” submenu to the MarkEdit extension UI so users can manually trigger proofreading actions and navigate to release information, following the menu registration pattern used by MarkEdit extensions.

Changes:

  • Injects __PKG_VERSION__ at build time via Vite and declares its TypeScript global type.
  • Introduces src/menu.ts to build a parent “Proofread” menu with child actions (“Proofread Now”, “Ignore All”, version, releases link).
  • Registers the menu in main.ts and adds a Vitest test to validate the menu structure.

Reviewed changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vite.config.mts Defines __PKG_VERSION__ from package.json for build-time replacement.
types/globals.d.ts Declares the global __PKG_VERSION__ type for TS.
tsconfig.json Enables JSON module resolution needed for importing package.json.
src/menu.ts Implements the “Proofread” menu structure and wires actions to lint/diagnostics.
src/extension.ts Uses doc.toString() to read full document text during scheduled linting.
src/const.ts Adds repoUrl constant for GitHub release links.
main.ts Registers the menu item with MarkEdit.addMainMenuItem(...).
tests/menu.test.ts Verifies parent/child menu structure and action presence.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/menu.ts
Comment thread tests/menu.test.ts
@cyanzhong cyanzhong marked this pull request as ready for review March 14, 2026 10:41
@cyanzhong cyanzhong merged commit 967c324 into main Mar 14, 2026
7 checks passed
@cyanzhong cyanzhong deleted the copilot/add-proofreading-menu-item branch March 14, 2026 10:56
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.

Extension menu item

3 participants