11import * as vscode from "vscode" ;
22import { randomUUID } from "crypto" ;
33import { getPromptCompletion } from "../prompt" ;
4- import { abortInterval , delay } from "../utils/intervals" ;
4+ import { abortInterval , delay } from "./utils/intervals" ;
5+ import { getAdditionalDocuments } from "./utils/getAdditionalDocuments" ;
56import Logger from "../logger" ;
67import { sendCompletionRequest } from "./localCompletion" ;
78import { servers } from "../server" ;
@@ -23,6 +24,7 @@ export const getInlineCompletionProvider = (
2324) => {
2425 let maxToken = 50 ;
2526 let expectedTime = 1000 ;
27+
2628 const provider : vscode . InlineCompletionItemProvider = {
2729 provideInlineCompletionItems : async (
2830 document ,
@@ -32,15 +34,19 @@ export const getInlineCompletionProvider = (
3234 ) => {
3335 const triggerAuto =
3436 context . triggerKind === vscode . InlineCompletionTriggerKind . Automatic ;
37+
3538 const currentInlineSuggestModeAuto = state . workspace . get (
3639 "inlineSuggestModeAuto"
3740 ) ;
41+
3842 if ( currentInlineSuggestModeAuto !== true && triggerAuto === true ) {
3943 return [ ] ;
4044 }
45+
4146 if ( context . selectedCompletionInfo ) {
4247 return [ ] ;
4348 }
49+
4450 const loggerCompletion = logCompletion ( ) ;
4551
4652 loggerCompletion . info ( "Completion: started" ) ;
@@ -50,57 +56,39 @@ export const getInlineCompletionProvider = (
5056 loggerCompletion . info ( "Completion: canceled" ) ;
5157 return [ ] ;
5258 }
59+
5360 const { abortController, requestFinish } = abortInterval ( token ) ;
5461
5562 const modelType = triggerAuto
5663 ? configuration . get ( "completion.autoMode" )
5764 : configuration . get ( "completion.manuallyMode" ) ;
5865
59- const serverUrl = configuration . get ( "cloud.use" )
60- ? configuration . get ( "cloud.endpoint" )
61- : servers [ modelType ] . serverUrl ;
62-
63- let additionalDocuments : vscode . TextDocument [ ] = [ ] ;
64-
65- if ( configuration . get ( "experimental.useopentabs" ) ) {
66- const additionalDocumentsUri = vscode . window . tabGroups . all
67- . map ( ( group ) => group . tabs )
68- . flat ( )
69- . filter ( ( tab ) => ! ( tab . group . isActive && tab . isActive ) )
70- . filter (
71- ( tab ) =>
72- tab . input &&
73- "uri" in ( tab . input as any ) &&
74- ( ( tab . input as any ) . uri as vscode . Uri ) . scheme === "file"
75- )
76- . map ( ( tab ) => ( tab . input as any ) . uri as vscode . Uri ) ;
77- additionalDocuments = await Promise . all (
78- additionalDocumentsUri . map ( ( uri ) =>
79- vscode . workspace . openTextDocument ( uri )
80- )
81- ) ;
82- }
66+ const serverUrl = servers [ modelType ] . serverUrl ;
67+
68+ const additionalDocuments : vscode . TextDocument [ ] = configuration . get (
69+ "experimental.useopentabs"
70+ )
71+ ? await getAdditionalDocuments ( )
72+ : [ ] ;
8373
8474 const prompt = await getPromptCompletion ( {
8575 activeDocument : document ,
8676 additionalDocuments : additionalDocuments ,
8777 position : position ,
88- maxTokenExpect :
89- triggerAuto && ! configuration . get ( "cloud.use" ) ? maxToken : 2000 ,
78+ maxTokenExpect : triggerAuto ? maxToken : 2000 ,
9079 url : serverUrl ,
9180 } ) ;
9281
93- const parameters =
94- triggerAuto && ! configuration . get ( "cloud.use" )
95- ? {
96- n_predict : 128 ,
97- stop : [ "\n" ] ,
98- }
99- : {
100- n_predict : 512 ,
101- stop : [ ] ,
102- temperature : 0.5 ,
103- } ;
82+ const parameters = triggerAuto
83+ ? {
84+ n_predict : 128 ,
85+ stop : [ "\n" ] ,
86+ }
87+ : {
88+ n_predict : 512 ,
89+ stop : [ ] ,
90+ temperature : 0.5 ,
91+ } ;
10492
10593 try {
10694 Logger . info (
0 commit comments