@@ -13,6 +13,7 @@ import {
13
13
TextDocument ,
14
14
ResponseError ,
15
15
LSPErrorCodes ,
16
+ WorkspaceFolder ,
16
17
} from '@aws/language-server-runtimes/server-interface'
17
18
import { AWSError } from 'aws-sdk'
18
19
import { autoTrigger , triggerType } from './auto-trigger/autoTrigger'
@@ -56,13 +57,15 @@ import { UserWrittenCodeTracker } from '../../shared/userWrittenCodeTracker'
56
57
57
58
const EMPTY_RESULT = { sessionId : '' , items : [ ] }
58
59
export const FILE_URI_CHARS_LIMIT = 1024
60
+ export const FILENAME_CHARS_LIMIT = 1024
59
61
export const CONTEXT_CHARACTERS_LIMIT = 10240
60
62
61
63
// Both clients (token, sigv4) define their own types, this return value needs to match both of them.
62
64
const getFileContext = ( params : {
63
65
textDocument : TextDocument
64
66
position : Position
65
67
inferredLanguageId : CodewhispererLanguage
68
+ workspaceFolder : WorkspaceFolder | null | undefined
66
69
} ) : {
67
70
fileUri : string
68
71
filename : string
@@ -81,18 +84,13 @@ const getFileContext = (params: {
81
84
end : params . textDocument . positionAt ( params . textDocument . getText ( ) . length ) ,
82
85
} )
83
86
84
- let relativeFileName = params . textDocument . uri
85
- relativeFileName = path . basename ( params . textDocument . uri )
86
- // const workspaceFolder = WorkspaceFolderManager.getInstance()?.getWorkspaceFolder(params.textDocument.uri)
87
- // if (workspaceFolder) {
88
- // relativeFileName = getRelativePath(workspaceFolder, params.textDocument.uri)
89
- // } else {
90
- // relativeFileName = path.basename(params.textDocument.uri)
91
- // }
87
+ const relativeFilePath = params . workspaceFolder
88
+ ? getRelativePath ( params . workspaceFolder , params . textDocument . uri )
89
+ : path . basename ( params . textDocument . uri )
92
90
93
91
return {
94
92
fileUri : params . textDocument . uri . substring ( 0 , FILE_URI_CHARS_LIMIT ) ,
95
- filename : relativeFileName ,
93
+ filename : relativeFilePath . substring ( 0 , FILENAME_CHARS_LIMIT ) ,
96
94
programmingLanguage : {
97
95
languageName : getRuntimeLanguage ( params . inferredLanguageId ) ,
98
96
} ,
@@ -346,7 +344,12 @@ export const CodewhispererServerFactory =
346
344
params . context . triggerKind == InlineCompletionTriggerKind . Automatic
347
345
const maxResults = isAutomaticLspTriggerKind ? 1 : 5
348
346
const selectionRange = params . context . selectedCompletionInfo ?. range
349
- const fileContext = getFileContext ( { textDocument, inferredLanguageId, position : params . position } )
347
+ const fileContext = getFileContext ( {
348
+ textDocument,
349
+ inferredLanguageId,
350
+ position : params . position ,
351
+ workspaceFolder : workspace . getWorkspaceFolder ( textDocument . uri ) ,
352
+ } )
350
353
const workspaceState = WorkspaceFolderManager . getInstance ( ) ?. getWorkspaceState ( )
351
354
const workspaceId = workspaceState ?. webSocketClient ?. isConnected ( )
352
355
? workspaceState . workspaceId
0 commit comments