-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from leftmove/google-provider
feat(google): added gemini api as provider
- Loading branch information
Showing
23 changed files
with
501 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
"@anthropic-ai/sdk": "^0.27.3", | ||
"@commitlint/cli": "^19.5.0", | ||
"@commitlint/config-conventional": "^19.5.0", | ||
"@google/generative-ai": "^0.21.0", | ||
"@ianvs/prettier-plugin-sort-imports": "^4.2.1", | ||
"@release-it/conventional-changelog": "^8.0.2", | ||
"@typescript-eslint/eslint-plugin": "^7.3.1", | ||
|
@@ -60,5 +61,6 @@ | |
} | ||
], | ||
"license": "MIT", | ||
"author": "Arshad Yaseen <[email protected]> (https://arshadyaseen.com)" | ||
"author": "Arshad Yaseen <[email protected]> (https://arshadyaseen.com)", | ||
"dependencies": {} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import {CursorPosition, EditorModel, EditorRange, Monaco} from '../types'; | ||
|
||
export class CompletionRange { | ||
private monaco: Monaco; | ||
|
||
constructor(monaco: Monaco) { | ||
this.monaco = monaco; | ||
} | ||
|
||
public computeInsertionRange( | ||
pos: CursorPosition, | ||
completion: string, | ||
mdl: EditorModel, | ||
): EditorRange { | ||
// Handle empty completion | ||
if (!completion) { | ||
return new this.monaco.Range( | ||
pos.lineNumber, | ||
pos.column, | ||
pos.lineNumber, | ||
pos.column, | ||
); | ||
} | ||
|
||
const startOffset = mdl.getOffsetAt(pos); | ||
const textBeforeCursor = mdl.getValue().substring(0, startOffset); | ||
const textAfterCursor = mdl.getValue().substring(startOffset); | ||
|
||
let prefixOverlapLength = 0; | ||
let suffixOverlapLength = 0; | ||
let maxOverlapLength = 0; | ||
let startOverlapLength = 0; | ||
|
||
const completionLength = completion.length; | ||
const beforeLength = textBeforeCursor.length; | ||
const afterLength = textAfterCursor.length; | ||
|
||
// Handle cursor at the end of the document | ||
if (startOffset >= mdl.getValue().length) { | ||
return new this.monaco.Range( | ||
pos.lineNumber, | ||
pos.column, | ||
pos.lineNumber, | ||
pos.column, | ||
); | ||
} | ||
|
||
// Handle empty remaining text | ||
if (afterLength === 0) { | ||
return new this.monaco.Range( | ||
pos.lineNumber, | ||
pos.column, | ||
pos.lineNumber, | ||
pos.column, | ||
); | ||
} | ||
|
||
// Find overlap with text before cursor | ||
const maxBeforeOverlap = Math.min(completionLength, beforeLength); | ||
for (let i = 1; i <= maxBeforeOverlap; i++) { | ||
const completionStart = completion.substring(0, i); | ||
const textEnd = textBeforeCursor.slice(-i); | ||
if (completionStart === textEnd) { | ||
startOverlapLength = i; | ||
} | ||
} | ||
|
||
// Find overlap with text after cursor | ||
const maxAfterOverlap = Math.min(completionLength, afterLength); | ||
|
||
// Find the longest prefix overlap with text after cursor | ||
for (let i = 0; i < maxAfterOverlap; i++) { | ||
if (completion[i] !== textAfterCursor[i]) break; | ||
prefixOverlapLength++; | ||
} | ||
|
||
// Find the longest suffix overlap with text after cursor | ||
for (let i = 1; i <= maxAfterOverlap; i++) { | ||
if (completion.slice(-i) === textAfterCursor.slice(0, i)) { | ||
suffixOverlapLength = i; | ||
} | ||
} | ||
|
||
maxOverlapLength = Math.max(prefixOverlapLength, suffixOverlapLength); | ||
|
||
// Check for internal overlaps if no prefix or suffix overlap | ||
if (maxOverlapLength === 0) { | ||
for (let i = 1; i < completionLength; i++) { | ||
if (textAfterCursor.startsWith(completion.substring(i))) { | ||
maxOverlapLength = completionLength - i; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
// Calculate start and end positions | ||
const startPosition = | ||
startOverlapLength > 0 | ||
? mdl.getPositionAt(startOffset - startOverlapLength) | ||
: pos; | ||
const endOffset = startOffset + maxOverlapLength; | ||
const endPosition = mdl.getPositionAt(endOffset); | ||
|
||
return new this.monaco.Range( | ||
startPosition.lineNumber, | ||
startPosition.column, | ||
endPosition.lineNumber, | ||
endPosition.column, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.