Skip to content

Allow tasks to be run via terminal suggest #252002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 20, 2025

This PR implements task completions in the terminal suggest widget, allowing users to type task names and run them directly from terminal suggestions.

Changes Made

Core Implementation

  • New Task Completion Provider: Created TaskCompletionProvider that implements ITerminalCompletionProvider to provide task suggestions based on user input
  • Task Execution Support: Extended ITerminalCompletion interface with command execution capability and modified SuggestAddon to execute tasks instead of inserting text
  • Smart Filtering: Tasks are filtered by:
    • Task labels starting with user input (e.g., "build" matches "build task")
    • Individual words in task labels (e.g., "build" matches "vs code build")
    • npm script names in command arguments for better npm task discovery

User Experience

  • Proper Positioning: Tasks appear below other completion types but above file/folder suggestions as requested
  • Task Icons: Uses tools icon (🔧) for all task completions
  • Command Execution: When selected, tasks execute via workbench.action.tasks.runTask command rather than inserting text into terminal
  • Edge Cases: Handles tasks with spaces in labels and npm scripts correctly

Integration

  • Provider Registration: Registered as built-in provider in terminal suggest contributions
  • Configuration: Added builtinTasks to default enabled providers
  • Sorting Logic: Added task-specific sorting to position tasks appropriately in suggestion list

Example Usage

When a user types "build" in the terminal, they now see:

Task suggestions showing build tasks

Selecting a task suggestion executes the task immediately instead of just inserting the task name.

Testing

Added comprehensive unit tests covering:

  • Task filtering by label and command arguments
  • Edge cases like tasks with spaces and npm scripts
  • Proper completion metadata (icons, details, commands)
  • Provider behavior with various input scenarios

Fixes #252001.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • electronjs.org
    • Triggering command: node-gyp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 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.

Copilot AI and others added 4 commits June 20, 2025 16:58
Co-authored-by: Tyriar <2193314+Tyriar@users.noreply.github.com>
Co-authored-by: Tyriar <2193314+Tyriar@users.noreply.github.com>
Co-authored-by: Tyriar <2193314+Tyriar@users.noreply.github.com>
Co-authored-by: Tyriar <2193314+Tyriar@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Allow tasks to be run via terminal suggest Allow tasks to be run via terminal suggest Jun 20, 2025
@Copilot Copilot AI requested a review from Tyriar June 20, 2025 17:09
Copilot finished work on behalf of Tyriar June 20, 2025 17:09
@@ -22,6 +22,7 @@ export enum TerminalCompletionItemKind {
// Kinds only for core
InlineSuggestion = 100,
InlineSuggestionAlwaysOnTop = 101,
Task = 102,
Copy link
Member

Choose a reason for hiding this comment

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

We want to support generic "VscodeCommand" kinds in the extension API too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed from Task to VscodeCommand to support generic command kinds in the extension API. This makes the enum more generic and extensible for future command-based completions. Changes made in commit 76623a8.

@@ -80,6 +80,7 @@ export const terminalSuggestConfiguration: IStringDictionary<IConfigurationPrope
'terminal-suggest': true,
'pwsh-shell-integration': true,
'lsp': true,
'builtinTasks': true,
Copy link
Member

Choose a reason for hiding this comment

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

This should just be 'tasks'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed from 'builtinTasks' to 'tasks' in the default configuration. Updated in commit 76623a8.

import { ThemeIcon } from '../../../../../base/common/themables.js';
import { Codicon } from '../../../../../base/common/codicons.js';

export class TaskCompletionProvider implements ITerminalCompletionProvider {
Copy link
Member

Choose a reason for hiding this comment

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

Could we move all the task completion provider into a new terminalContrib/task/ folder? Make sure the new terminal contrib is included in src\vs\workbench\contrib\terminal\terminal.all.ts. Follow these principles:

  • terminalContrib/suggest/ should know about command-based completions
  • terminalContrib/task/ should know about tasks and provide command-based completions to terminalContrib/suggest/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the task completion provider to new terminalContrib/task/ folder structure following the requested architecture:

  • terminalContrib/suggest/ now knows about command-based completions via VscodeCommand kind
  • terminalContrib/task/ provides command-based completions to suggest
  • Added the new terminal contrib to terminal.all.ts
  • Updated all import paths and references
    Changes implemented in commit 76623a8.

…lder, change config key

Co-authored-by: Tyriar <2193314+Tyriar@users.noreply.github.com>
Copilot finished work on behalf of Tyriar June 20, 2025 19:39
@Copilot Copilot AI requested a review from Tyriar June 20, 2025 19:39
Comment on lines 27 to 35
// Get the text up to the cursor position
const prefix = value.substring(0, cursorPosition);
const words = prefix.trim().split(/\s+/);

// Only suggest tasks if we're at the beginning of a command or it's a single word
// This prevents tasks from appearing in the middle of complex commands
if (words.length > 1 && prefix.trim() !== words[0]) {
return [];
}
Copy link
Member

Choose a reason for hiding this comment

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

No filtering here is needed, that's handled by the suggest code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the complex filtering logic in provideCompletions method as requested. The terminal suggest system now handles all the filtering automatically. Changes implemented in commit 529ae9d.

Comment on lines 31 to 37
// Only suggest tasks if we're at the beginning of a command or it's a single word
// This prevents tasks from appearing in the middle of complex commands
if (words.length > 1 && prefix.trim() !== words[0]) {
return [];
}

const currentWord = words[words.length - 1] || '';
Copy link
Member

Choose a reason for hiding this comment

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

This and _shouldIncludeTask should actually do very little filtering. In general the suggestion should be provided when either:

  • There are no spaces in value
  • The words before cursorPosition (except the word that the cursor is on) match the text of the task exactly. For example "VS Code" and then the cursor position, should include all tasks with labels that start with "VS Code"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified the filtering logic in _shouldIncludeTask as requested. Now it only does minimal filtering:

  • Shows all tasks when there are no spaces in the input
  • For multi-word input, only shows tasks where the preceding words match the task label exactly (e.g., "VS Code" cursor position shows tasks starting with "VS Code")

Updated the corresponding tests to match the new behavior. Changes in commit 529ae9d.

Co-authored-by: Tyriar <2193314+Tyriar@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 20, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • electronjs.org
    • Triggering command: node-gyp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI requested a review from Tyriar June 20, 2025 21:09
Copilot finished work on behalf of Tyriar June 20, 2025 21:09
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.

Allow tasks to be run via terminal suggest
2 participants