Skip to content

Commit

Permalink
Merge pull request #186 from rjmacarthy/development
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
rjmacarthy committed Mar 22, 2024
2 parents 10f984f + 381422d commit abe2ba6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 34 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "twinny",
"displayName": "twinny - AI Code Completion and Chat",
"description": "Locally hosted AI code completion plugin for vscode",
"version": "3.8.15",
"version": "3.8.17",
"icon": "assets/icon.png",
"keywords": [
"code-inference",
Expand Down
13 changes: 9 additions & 4 deletions src/extension/completion-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,14 @@ export class CompletionFormatter {
return this._completion
}

private trimSingleWord = () => {
if (/^ [^ ]+$/.test(this._completion)) {
this._completion = this._completion.trim()
private trimStart = () => {
const firstNonSpaceIndex = this._completion.search(/\S/)

if (
firstNonSpaceIndex > 0 &&
this._cursorPosition.character <= firstNonSpaceIndex
) {
this._completion = this._completion.trimStart()
}
return this
}
Expand Down Expand Up @@ -274,7 +279,7 @@ export class CompletionFormatter {
.skipMiddleOfWord()
.skipSimilarCompletions()
.ignoreContextCompletionAtStartOrEnd()
.trimSingleWord()
.trimStart()
.getCompletion()
return infillText
}
Expand Down
22 changes: 0 additions & 22 deletions src/extension/parser-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,6 @@ export const getIsDeclarationType = (node: SyntaxNode) => {
return false
}

export const injectCompletionToNode = (
node: SyntaxNode | undefined | null,
completion: string
) => {
if (!node || !completion) {
return ''
}

const parts = node.text.split('\n')

const lastPart = parts[parts.length - 1]

if (DECLARATION_TYPE.includes(lastPart)) {
parts.pop()
}

return parts
.map((text: string) => text.trim())
.filter(Boolean)
.join(` ${completion} `)
}

export const getIsMultiLineCompletionNode = (node: SyntaxNode | null) => {
if (!node) return false

Expand Down
11 changes: 6 additions & 5 deletions src/extension/providers/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,23 +436,23 @@ export class CompletionProvider implements InlineCompletionItemProvider {

if (!editor || !this._position) return []

const insertText = new CompletionFormatter(editor).format(this._completion)
const completionText = new CompletionFormatter(editor).format(this._completion)

if (this._cacheEnabled) cache.setCache(prefixSuffix, insertText)
if (this._cacheEnabled) cache.setCache(prefixSuffix, completionText)

this._logger.log(
`\n Inline completion triggered: Formatted completion: ${JSON.stringify(
insertText
completionText
)}\n`
)

this._statusBar.text = '🤖'
this._lastCompletionText = insertText
this._lastCompletionText = completionText
this._lastCompletionMultiline = this._isMultiLineCompletion

return [
new InlineCompletionItem(
insertText,
completionText,
new Range(this._position, this._position)
)
]
Expand All @@ -473,6 +473,7 @@ export class CompletionProvider implements InlineCompletionItemProvider {
this._fimModel = this._config.get('fimModelName') as string
this._fimTemplateFormat = this._config.get('fimTemplateFormat') as string
this._keepAlive = this._config.get('keepAlive') as string | number
this._maxLines = this._config.get('maxLines') as number
this._numLineContext = this._config.get('contextLength') as number
this._numPredictFim = this._config.get('numPredictFim') as number
this._port = this._config.get('fimApiPort') as number
Expand Down

0 comments on commit abe2ba6

Please sign in to comment.