Skip to content

Commit

Permalink
parse on every line break is better
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmacarthy committed Apr 24, 2024
1 parent 54021e4 commit 80882a4
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions src/extension/providers/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,35 +288,36 @@ export class CompletionProvider implements InlineCompletionItemProvider {
const lineText = getCurrentLineText(this._position) || ''
if (!this._parser) return ''

// TODO: Rethink as can cause vscode to hang when parser throws error.
const { rootNode } = this._parser.parse(
`${lineText}${this._completion}`
)

const { hasError } = rootNode

if (
this._parser &&
this._nodeAtPosition &&
this._isMultilineCompletion &&
this._chunkCount >= 2 &&
takeFirst &&
!hasError
) {
if (providerFimData.includes('\n')) {
console.log('parse')
const { rootNode } = this._parser.parse(
`${lineText}${this._completion}`
)

const { hasError } = rootNode

if (
MULTI_LINE_DELIMITERS.some((delimiter) =>
this._completion.endsWith(delimiter)
)
this._parser &&
this._nodeAtPosition &&
this._isMultilineCompletion &&
this._chunkCount >= 2 &&
takeFirst &&
!hasError
) {
this._logger.log(
`Streaming response end due to delimiter ${this._nonce} \nCompletion: ${this._completion}`
)
return this._completion
if (
MULTI_LINE_DELIMITERS.some((delimiter) =>
this._completion.endsWith(delimiter)
)
) {
this._logger.log(
`Streaming response end due to delimiter ${this._nonce} \nCompletion: ${this._completion}`
)
return this._completion
}
}
}
}
} catch (e) {
// Currently doesnt catch
} catch (e) { // Currently doesnt catch when parser fucks up
console.error(e)
this.abortCompletion()
}
Expand Down

0 comments on commit 80882a4

Please sign in to comment.