Skip to content

Commit 09c9fda

Browse files
asiloisadclaude
andcommitted
Fix autocomplete-plus crash with non-workspace editors
The subsequence-provider crashes when autocomplete is triggered in editors that are not part of the workspace (e.g., watch pane editors in hydrogen-next). This happens because the editor buffer is not tracked in watchedBuffers. Changes: - Add guard in bufferToSubsequenceMatches to return empty results for untracked buffers instead of crashing - Filter buffers in getSuggestions to only include those in watchedBuffers - Add null check in subsequenceMatchToType for safety Fixes crashes when using autocomplete.watchEditor API with non-workspace editors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f7963ca commit 09c9fda

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

packages/autocomplete-plus/lib/subsequence-provider.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ class SubsequenceProvider {
133133
}
134134

135135
bufferToSubsequenceMatches (prefix, additionalWordCharacters, buffer) {
136-
const position = this.watchedBuffers.get(buffer).getCursorBufferPosition()
136+
const editor = this.watchedBuffers.get(buffer)
137+
// Guard against buffers that aren't in watchedBuffers (e.g., non-workspace editors)
138+
if (!editor) {
139+
return Promise.resolve([])
140+
}
141+
const position = editor.getCursorBufferPosition()
137142
const searchRange = this.clampedRange(
138143
this.maxSearchRowDelta,
139144
position.row,
@@ -160,9 +165,13 @@ class SubsequenceProvider {
160165
return
161166
}
162167

163-
const buffers = this.includeCompletionsFromAllBuffers
168+
// Get buffers to search for completions
169+
// Filter to only include buffers that are in watchedBuffers to avoid errors
170+
// with non-workspace editors (like watch pane editors)
171+
const requestedBuffers = this.includeCompletionsFromAllBuffers
164172
? Array.from(this.watchedBuffers.keys())
165173
: [editor.getBuffer()]
174+
const buffers = requestedBuffers.filter(buffer => this.watchedBuffers.has(buffer))
166175

167176
const currentEditorBuffer = editor.getBuffer()
168177

@@ -181,6 +190,7 @@ class SubsequenceProvider {
181190

182191
const subsequenceMatchToType = (match) => {
183192
const editor = this.watchedBuffers.get(match.buffer)
193+
if (!editor) return null
184194
const scopeDescriptor = editor.scopeDescriptorForBufferPosition(match.positions[0])
185195
return this.providerConfig.scopeDescriptorToType(scopeDescriptor)
186196
}

0 commit comments

Comments
 (0)