Skip to content

Commit

Permalink
Edit: Add maximum timeout to formatter logic (#4113)
Browse files Browse the repository at this point in the history
  • Loading branch information
umpox committed May 9, 2024
1 parent fb5fc30 commit 35b10fb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
9 changes: 9 additions & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ This is a log of all notable changes to Cody for VS Code. [Unreleased] changes a

### Added

- Search: A new `Search Code` command added to the `Commands` sidebar for Cody's Natural Language Search. [pull/3991](https://github.com/sourcegraph/cody/pull/3991)
- Context Menu: Added commands to send file to chat as @-mention from the explorer context menu. [pull/4000](https://github.com/sourcegraph/cody/pull/4000)
- `Add File to Chat`: Add file to the current opened chat, or start a new chat if no panel is opened.
- `New Chat with File Content`: Opens a new chat with the file content when no existing chat panel is open.
- Chat: New optimization for prompt quality and token usage, deduplicating context items, and optimizing token allocation. [pull/3929](https://github.com/sourcegraph/cody/pull/3929)
- Document Code/Generate Tests: User selections are now matched against known symbol ranges, and adjusted in cases where a user selection in a suitable subset of one of these ranges. [pull/4031](https://github.com/sourcegraph/cody/pull/4031)
- Edit: Added a maximum timeout to the formatting logic, so the Edit does not appear stuck if the users' formatter takes a particularly long amount of tiem. [pull/4113](https://github.com/sourcegraph/cody/pull/4113)
- Extension: Added the `vscode.git` extension to the `extensionDependencies` list. [pull/4110](https://github.com/sourcegraph/cody/pull/4110)

### Fixed

- Autocomplete: Handle incomplete Ollama response chunks gracefully. [pull/4066](https://github.com/sourcegraph/cody/pull/4066)
Expand Down
29 changes: 21 additions & 8 deletions vscode/src/non-stop/FixupController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { countCode } from '../services/utils/code-count'

import { PersistenceTracker } from '../common/persistence-tracker'
import { lines } from '../completions/text-processing'
import { sleep } from '../completions/utils'
import { getInput } from '../edit/input/get-input'
import type { ExtensionClient } from '../extension-client'
import type { AuthProvider } from '../services/AuthProvider'
Expand Down Expand Up @@ -867,15 +868,27 @@ export class FixupController
return false
}

/**
* Maximum amount of time to spend formatting.
* If the formatter takes longer than this then we will skip formatting completely.
*/
const formattingTimeout = 1000
const formattingChanges =
(await vscode.commands.executeCommand<vscode.TextEdit[]>(
'vscode.executeFormatDocumentProvider',
document.uri,
{
tabSize: getEditorTabSize(document.uri, vscode.workspace, vscode.window),
insertSpaces: getEditorInsertSpaces(document.uri, vscode.workspace, vscode.window),
} satisfies vscode.FormattingOptions
)) || []
(await Promise.race([
vscode.commands.executeCommand<vscode.TextEdit[]>(
'vscode.executeFormatDocumentProvider',
document.uri,
{
tabSize: getEditorTabSize(document.uri, vscode.workspace, vscode.window),
insertSpaces: getEditorInsertSpaces(
document.uri,
vscode.workspace,
vscode.window
),
}
),
sleep(formattingTimeout),
])) || []

const formattingChangesInRange = formattingChanges.filter(change =>
rangeToFormat.contains(change.range)
Expand Down

0 comments on commit 35b10fb

Please sign in to comment.