| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import type {ServerPlatform} from 'isl-server/src/serverPlatform'; |
| b69ab31 | | | 9 | import type {RepositoryContext} from 'isl-server/src/serverTypes'; |
| b69ab31 | | | 10 | import type { |
| b69ab31 | | | 11 | AbsolutePath, |
| b69ab31 | | | 12 | Diagnostic, |
| b69ab31 | | | 13 | DiagnosticSeverity, |
| b69ab31 | | | 14 | PlatformSpecificClientToServerMessages, |
| b69ab31 | | | 15 | RepoRelativePath, |
| b69ab31 | | | 16 | ServerToClientMessage, |
| b69ab31 | | | 17 | } from 'isl/src/types'; |
| b69ab31 | | | 18 | import type {Json} from 'shared/typeUtils'; |
| b69ab31 | | | 19 | |
| b69ab31 | | | 20 | import {Repository} from 'isl-server/src/Repository'; |
| b69ab31 | | | 21 | import type {CodeReviewIssue} from 'isl/src/firstPassCodeReview/types'; |
| b69ab31 | | | 22 | import {arraysEqual} from 'isl/src/utils'; |
| b69ab31 | | | 23 | import * as pathModule from 'node:path'; |
| b69ab31 | | | 24 | import * as vscode from 'vscode'; |
| b69ab31 | | | 25 | import {executeVSCodeCommand} from './commands'; |
| b69ab31 | | | 26 | import {PERSISTED_STORAGE_KEY_PREFIX} from './config'; |
| b69ab31 | | | 27 | import {t} from './i18n'; |
| b69ab31 | | | 28 | import {Internal} from './Internal'; |
| b69ab31 | | | 29 | import {openFileInRepo} from './openFile'; |
| b69ab31 | | | 30 | import {ActionTriggerType} from './types'; |
| b69ab31 | | | 31 | |
| b69ab31 | | | 32 | export type VSCodeServerPlatform = ServerPlatform & { |
| b69ab31 | | | 33 | panelOrView: undefined | vscode.WebviewPanel | vscode.WebviewView; |
| b69ab31 | | | 34 | }; |
| b69ab31 | | | 35 | |
| b69ab31 | | | 36 | function diagnosticSeverity(severity: vscode.DiagnosticSeverity): DiagnosticSeverity { |
| b69ab31 | | | 37 | switch (severity) { |
| b69ab31 | | | 38 | case vscode.DiagnosticSeverity.Error: |
| b69ab31 | | | 39 | return 'error'; |
| b69ab31 | | | 40 | case vscode.DiagnosticSeverity.Warning: |
| b69ab31 | | | 41 | return 'warning'; |
| b69ab31 | | | 42 | case vscode.DiagnosticSeverity.Information: |
| b69ab31 | | | 43 | return 'info'; |
| b69ab31 | | | 44 | case vscode.DiagnosticSeverity.Hint: |
| b69ab31 | | | 45 | return 'hint'; |
| b69ab31 | | | 46 | } |
| b69ab31 | | | 47 | } |
| b69ab31 | | | 48 | |
| b69ab31 | | | 49 | export const getVSCodePlatform = (context: vscode.ExtensionContext): VSCodeServerPlatform => ({ |
| b69ab31 | | | 50 | platformName: 'vscode', |
| b69ab31 | | | 51 | sessionId: vscode.env.sessionId, |
| b69ab31 | | | 52 | panelOrView: undefined, |
| b69ab31 | | | 53 | async handleMessageFromClient( |
| b69ab31 | | | 54 | this: VSCodeServerPlatform, |
| b69ab31 | | | 55 | repo: Repository | undefined, |
| b69ab31 | | | 56 | ctx: RepositoryContext, |
| b69ab31 | | | 57 | message: PlatformSpecificClientToServerMessages, |
| b69ab31 | | | 58 | postMessage: (message: ServerToClientMessage) => void, |
| b69ab31 | | | 59 | onDispose: (cb: () => unknown) => void, |
| b69ab31 | | | 60 | ) { |
| b69ab31 | | | 61 | try { |
| b69ab31 | | | 62 | switch (message.type) { |
| b69ab31 | | | 63 | case 'platform/openFiles': { |
| b69ab31 | | | 64 | for (const path of message.paths) { |
| b69ab31 | | | 65 | if (repo == null) { |
| b69ab31 | | | 66 | return; |
| b69ab31 | | | 67 | } |
| b69ab31 | | | 68 | // don't use preview mode for opening multiple files, since they would overwrite each other |
| b69ab31 | | | 69 | openFileInRepo( |
| b69ab31 | | | 70 | repo, |
| b69ab31 | | | 71 | path, |
| b69ab31 | | | 72 | message.options?.line, |
| b69ab31 | | | 73 | /* preview */ false, |
| b69ab31 | | | 74 | /* onError */ (err: Error) => { |
| b69ab31 | | | 75 | // Opening multiple files at once can throw errors even when the files are successfully opened |
| b69ab31 | | | 76 | // We check here if the error is unwarranted and the file actually exists in the tab group |
| b69ab31 | | | 77 | const uri = vscode.Uri.file(pathModule.join(repo.info.repoRoot, path)); |
| b69ab31 | | | 78 | const isTabOpen = vscode.window.tabGroups.all |
| b69ab31 | | | 79 | .flatMap(group => group.tabs) |
| b69ab31 | | | 80 | .some( |
| b69ab31 | | | 81 | tab => |
| b69ab31 | | | 82 | tab.input instanceof vscode.TabInputText && |
| b69ab31 | | | 83 | uri.fsPath == tab.input.uri.fsPath, |
| b69ab31 | | | 84 | ); |
| b69ab31 | | | 85 | |
| b69ab31 | | | 86 | if (!isTabOpen) { |
| b69ab31 | | | 87 | vscode.window.showErrorMessage(err.message ?? String(err)); |
| b69ab31 | | | 88 | } |
| b69ab31 | | | 89 | }, |
| b69ab31 | | | 90 | ); |
| b69ab31 | | | 91 | } |
| b69ab31 | | | 92 | break; |
| b69ab31 | | | 93 | } |
| b69ab31 | | | 94 | case 'platform/openFile': { |
| b69ab31 | | | 95 | if (repo != null) { |
| b69ab31 | | | 96 | openFileInRepo(repo, message.path, message.options?.line, undefined); |
| b69ab31 | | | 97 | } |
| b69ab31 | | | 98 | break; |
| b69ab31 | | | 99 | } |
| b69ab31 | | | 100 | case 'platform/openDiff': { |
| b69ab31 | | | 101 | if (repo == null) { |
| b69ab31 | | | 102 | break; |
| b69ab31 | | | 103 | } |
| b69ab31 | | | 104 | const path: AbsolutePath = pathModule.join(repo.info.repoRoot, message.path); |
| b69ab31 | | | 105 | const uri = vscode.Uri.file(path); |
| b69ab31 | | | 106 | executeVSCodeCommand('sapling.open-file-diff', uri, message.comparison); |
| b69ab31 | | | 107 | break; |
| b69ab31 | | | 108 | } |
| b69ab31 | | | 109 | case 'platform/openExternal': { |
| b69ab31 | | | 110 | vscode.env.openExternal(vscode.Uri.parse(message.url)); |
| b69ab31 | | | 111 | break; |
| b69ab31 | | | 112 | } |
| b69ab31 | | | 113 | case 'platform/changeTitle': { |
| b69ab31 | | | 114 | if (this.panelOrView != null) { |
| b69ab31 | | | 115 | this.panelOrView.title = message.title; |
| b69ab31 | | | 116 | } |
| b69ab31 | | | 117 | break; |
| b69ab31 | | | 118 | } |
| b69ab31 | | | 119 | case 'platform/checkForDiagnostics': { |
| b69ab31 | | | 120 | const diagnosticMap = new Map<RepoRelativePath, Array<Diagnostic>>(); |
| b69ab31 | | | 121 | const repoRoot = repo?.info.repoRoot; |
| b69ab31 | | | 122 | if (repoRoot) { |
| b69ab31 | | | 123 | for (const path of message.paths) { |
| b69ab31 | | | 124 | const uri = vscode.Uri.file(pathModule.join(repoRoot, path)); |
| b69ab31 | | | 125 | const diagnostics = vscode.languages.getDiagnostics(uri); |
| b69ab31 | | | 126 | if (diagnostics.length > 0) { |
| b69ab31 | | | 127 | diagnosticMap.set( |
| b69ab31 | | | 128 | path, |
| b69ab31 | | | 129 | diagnostics.map(diagnostic => ({ |
| b69ab31 | | | 130 | message: diagnostic.message, |
| b69ab31 | | | 131 | range: { |
| b69ab31 | | | 132 | startLine: diagnostic.range.start.line, |
| b69ab31 | | | 133 | startCol: diagnostic.range.start.character, |
| b69ab31 | | | 134 | endLine: diagnostic.range.end.line, |
| b69ab31 | | | 135 | endCol: diagnostic.range.end.character, |
| b69ab31 | | | 136 | }, |
| b69ab31 | | | 137 | severity: diagnosticSeverity(diagnostic.severity), |
| b69ab31 | | | 138 | source: diagnostic.source, |
| b69ab31 | | | 139 | code: |
| b69ab31 | | | 140 | typeof diagnostic.code === 'object' |
| b69ab31 | | | 141 | ? String(diagnostic.code.value) |
| b69ab31 | | | 142 | : String(diagnostic.code), |
| b69ab31 | | | 143 | })), |
| b69ab31 | | | 144 | ); |
| b69ab31 | | | 145 | } |
| b69ab31 | | | 146 | } |
| b69ab31 | | | 147 | } |
| b69ab31 | | | 148 | postMessage({type: 'platform/gotDiagnostics', diagnostics: diagnosticMap}); |
| b69ab31 | | | 149 | break; |
| b69ab31 | | | 150 | } |
| b69ab31 | | | 151 | case 'platform/confirm': { |
| b69ab31 | | | 152 | const OKButton = t('isl.confirmModalOK'); |
| b69ab31 | | | 153 | const result = await vscode.window.showInformationMessage( |
| b69ab31 | | | 154 | message.message, |
| b69ab31 | | | 155 | { |
| b69ab31 | | | 156 | detail: message.details, |
| b69ab31 | | | 157 | modal: true, |
| b69ab31 | | | 158 | }, |
| b69ab31 | | | 159 | OKButton, |
| b69ab31 | | | 160 | ); |
| b69ab31 | | | 161 | postMessage({type: 'platform/confirmResult', result: result === OKButton}); |
| b69ab31 | | | 162 | break; |
| b69ab31 | | | 163 | } |
| b69ab31 | | | 164 | case 'platform/subscribeToUnsavedFiles': { |
| b69ab31 | | | 165 | let previous: Array<{path: RepoRelativePath; uri: string}> = []; |
| b69ab31 | | | 166 | const postUnsavedFiles = () => { |
| b69ab31 | | | 167 | if (repo == null) { |
| b69ab31 | | | 168 | return; |
| b69ab31 | | | 169 | } |
| b69ab31 | | | 170 | const files = getUnsavedFiles(repo).map(document => { |
| b69ab31 | | | 171 | return { |
| b69ab31 | | | 172 | path: pathModule.relative(repo.info.repoRoot, document.fileName), |
| b69ab31 | | | 173 | uri: document.uri.toString(), |
| b69ab31 | | | 174 | }; |
| b69ab31 | | | 175 | }); |
| b69ab31 | | | 176 | |
| b69ab31 | | | 177 | if (!arraysEqual(files, previous)) { |
| b69ab31 | | | 178 | postMessage({ |
| b69ab31 | | | 179 | type: 'platform/unsavedFiles', |
| b69ab31 | | | 180 | unsaved: files, |
| b69ab31 | | | 181 | }); |
| b69ab31 | | | 182 | previous = files; |
| b69ab31 | | | 183 | } |
| b69ab31 | | | 184 | }; |
| b69ab31 | | | 185 | |
| b69ab31 | | | 186 | const disposables = [ |
| b69ab31 | | | 187 | vscode.workspace.onDidChangeTextDocument(postUnsavedFiles), |
| b69ab31 | | | 188 | vscode.workspace.onDidSaveTextDocument(postUnsavedFiles), |
| b69ab31 | | | 189 | ]; |
| b69ab31 | | | 190 | postUnsavedFiles(); |
| b69ab31 | | | 191 | onDispose(() => disposables.forEach(d => d.dispose())); |
| b69ab31 | | | 192 | break; |
| b69ab31 | | | 193 | } |
| b69ab31 | | | 194 | case 'platform/subscribeToSuggestedEdits': { |
| b69ab31 | | | 195 | const dispose = Internal.suggestedEdits?.onDidChangeSuggestedEdits( |
| b69ab31 | | | 196 | (files: Array<AbsolutePath>) => { |
| b69ab31 | | | 197 | postMessage({ |
| b69ab31 | | | 198 | type: 'platform/onDidChangeSuggestedEdits', |
| b69ab31 | | | 199 | files, |
| b69ab31 | | | 200 | }); |
| b69ab31 | | | 201 | }, |
| b69ab31 | | | 202 | ); |
| b69ab31 | | | 203 | onDispose(() => dispose?.dispose()); |
| b69ab31 | | | 204 | break; |
| b69ab31 | | | 205 | } |
| b69ab31 | | | 206 | case 'platform/resolveSuggestedEdits': { |
| b69ab31 | | | 207 | Internal.suggestedEdits?.resolveSuggestedEdits(message.action, message.files); |
| b69ab31 | | | 208 | break; |
| b69ab31 | | | 209 | } |
| b69ab31 | | | 210 | case 'platform/saveAllUnsavedFiles': { |
| b69ab31 | | | 211 | if (repo == null) { |
| b69ab31 | | | 212 | return; |
| b69ab31 | | | 213 | } |
| b69ab31 | | | 214 | Promise.all(getUnsavedFiles(repo).map(doc => doc.save())).then(results => { |
| b69ab31 | | | 215 | postMessage({ |
| b69ab31 | | | 216 | type: 'platform/savedAllUnsavedFiles', |
| b69ab31 | | | 217 | success: results.every(result => result), |
| b69ab31 | | | 218 | }); |
| b69ab31 | | | 219 | }); |
| b69ab31 | | | 220 | break; |
| b69ab31 | | | 221 | } |
| b69ab31 | | | 222 | case 'platform/subscribeToAvailableCwds': { |
| b69ab31 | | | 223 | const postAllAvailableCwds = async () => { |
| b69ab31 | | | 224 | const options = await Promise.all( |
| b69ab31 | | | 225 | (vscode.workspace.workspaceFolders ?? []).map(folder => { |
| b69ab31 | | | 226 | const cwd = folder.uri.fsPath; |
| b69ab31 | | | 227 | return Repository.getCwdInfo({...ctx, cwd}); |
| b69ab31 | | | 228 | }), |
| b69ab31 | | | 229 | ); |
| b69ab31 | | | 230 | postMessage({ |
| b69ab31 | | | 231 | type: 'platform/availableCwds', |
| b69ab31 | | | 232 | options, |
| b69ab31 | | | 233 | }); |
| b69ab31 | | | 234 | }; |
| b69ab31 | | | 235 | |
| b69ab31 | | | 236 | postAllAvailableCwds(); |
| b69ab31 | | | 237 | const dispose = vscode.workspace.onDidChangeWorkspaceFolders(postAllAvailableCwds); |
| b69ab31 | | | 238 | onDispose(() => dispose.dispose()); |
| b69ab31 | | | 239 | break; |
| b69ab31 | | | 240 | } |
| b69ab31 | | | 241 | case 'platform/setVSCodeConfig': { |
| b69ab31 | | | 242 | vscode.workspace |
| b69ab31 | | | 243 | .getConfiguration() |
| b69ab31 | | | 244 | .update( |
| b69ab31 | | | 245 | message.config, |
| b69ab31 | | | 246 | message.value, |
| b69ab31 | | | 247 | message.scope === 'global' |
| b69ab31 | | | 248 | ? vscode.ConfigurationTarget.Global |
| b69ab31 | | | 249 | : vscode.ConfigurationTarget.Workspace, |
| b69ab31 | | | 250 | ); |
| b69ab31 | | | 251 | break; |
| b69ab31 | | | 252 | } |
| b69ab31 | | | 253 | case 'platform/setPersistedState': { |
| b69ab31 | | | 254 | const {key, data} = message; |
| b69ab31 | | | 255 | context.globalState.update(PERSISTED_STORAGE_KEY_PREFIX + key, data); |
| b69ab31 | | | 256 | break; |
| b69ab31 | | | 257 | } |
| b69ab31 | | | 258 | case 'platform/subscribeToVSCodeConfig': { |
| b69ab31 | | | 259 | const sendLatestValue = () => |
| b69ab31 | | | 260 | postMessage({ |
| b69ab31 | | | 261 | type: 'platform/vscodeConfigChanged', |
| b69ab31 | | | 262 | config: message.config, |
| b69ab31 | | | 263 | value: vscode.workspace.getConfiguration().get<Json>(message.config), |
| b69ab31 | | | 264 | }); |
| b69ab31 | | | 265 | const dispose = vscode.workspace.onDidChangeConfiguration(e => { |
| b69ab31 | | | 266 | if (e.affectsConfiguration(message.config)) { |
| b69ab31 | | | 267 | sendLatestValue(); |
| b69ab31 | | | 268 | } |
| b69ab31 | | | 269 | }); |
| b69ab31 | | | 270 | sendLatestValue(); |
| b69ab31 | | | 271 | onDispose(() => dispose.dispose()); |
| b69ab31 | | | 272 | break; |
| b69ab31 | | | 273 | } |
| b69ab31 | | | 274 | case 'platform/executeVSCodeCommand': { |
| b69ab31 | | | 275 | vscode.commands.executeCommand(message.command, ...message.args); |
| b69ab31 | | | 276 | break; |
| b69ab31 | | | 277 | } |
| b69ab31 | | | 278 | case 'platform/resolveAllCommentsWithAI': { |
| b69ab31 | | | 279 | const {diffId, comments, filePaths, repoPath, userContext} = message; |
| b69ab31 | | | 280 | Internal.promptAIAgent?.( |
| b69ab31 | | | 281 | {type: 'resolveAllComments', diffId, comments, filePaths, repoPath, userContext}, |
| b69ab31 | | | 282 | ActionTriggerType.ISL2SmartActions, |
| b69ab31 | | | 283 | ); |
| b69ab31 | | | 284 | break; |
| b69ab31 | | | 285 | } |
| b69ab31 | | | 286 | case 'platform/resolveFailedSignalsWithAI': { |
| b69ab31 | | | 287 | const {diffId, diffVersionNumber, repoPath, userContext} = message; |
| b69ab31 | | | 288 | Internal.promptAIAgent?.( |
| b69ab31 | | | 289 | {type: 'resolveFailedSignals', diffId, diffVersionNumber, repoPath, userContext}, |
| b69ab31 | | | 290 | ActionTriggerType.ISL2SmartActions, |
| b69ab31 | | | 291 | ); |
| b69ab31 | | | 292 | break; |
| b69ab31 | | | 293 | } |
| b69ab31 | | | 294 | case 'platform/fillCommitMessageWithAI': { |
| b69ab31 | | | 295 | const {source, userContext} = message; |
| b69ab31 | | | 296 | Internal.promptAIAgent?.( |
| b69ab31 | | | 297 | {type: 'fillCommitMessage', userContext}, |
| b69ab31 | | | 298 | source === 'commitInfoView' |
| b69ab31 | | | 299 | ? ActionTriggerType.ISL2CommitInfoView |
| b69ab31 | | | 300 | : ActionTriggerType.ISL2SmartActions, |
| b69ab31 | | | 301 | ); |
| b69ab31 | | | 302 | break; |
| b69ab31 | | | 303 | } |
| b69ab31 | | | 304 | case 'platform/splitCommitWithAI': { |
| b69ab31 | | | 305 | const {diffCommit, args, repoPath, userContext} = message; |
| b69ab31 | | | 306 | Internal.promptAIAgent?.( |
| b69ab31 | | | 307 | {type: 'splitCommit', diffCommit, args, repoPath, userContext}, |
| b69ab31 | | | 308 | ActionTriggerType.ISL2SplitCommit, |
| b69ab31 | | | 309 | ); |
| b69ab31 | | | 310 | break; |
| b69ab31 | | | 311 | } |
| b69ab31 | | | 312 | case 'platform/createTestForModifiedCodeWithAI': { |
| b69ab31 | | | 313 | Internal.promptTestGeneration?.(); |
| b69ab31 | | | 314 | break; |
| b69ab31 | | | 315 | } |
| b69ab31 | | | 316 | case 'platform/recommendTestPlanWithAI': { |
| b69ab31 | | | 317 | const {commitHash, userContext} = message; |
| b69ab31 | | | 318 | Internal.promptAIAgent?.( |
| b69ab31 | | | 319 | {type: 'recommendTestPlan', commitHash, userContext}, |
| b69ab31 | | | 320 | ActionTriggerType.ISL2CommitInfoView, |
| b69ab31 | | | 321 | ); |
| b69ab31 | | | 322 | break; |
| b69ab31 | | | 323 | } |
| b69ab31 | | | 324 | case 'platform/generateSummaryWithAI': { |
| b69ab31 | | | 325 | const {commitHash, userContext} = message; |
| b69ab31 | | | 326 | Internal.promptAIAgent?.( |
| b69ab31 | | | 327 | {type: 'generateSummary', commitHash, userContext}, |
| b69ab31 | | | 328 | ActionTriggerType.ISL2CommitInfoView, |
| b69ab31 | | | 329 | ); |
| b69ab31 | | | 330 | break; |
| b69ab31 | | | 331 | } |
| b69ab31 | | | 332 | case 'platform/validateChangesWithAI': { |
| b69ab31 | | | 333 | const {userContext} = message; |
| b69ab31 | | | 334 | Internal.promptAIAgent?.( |
| b69ab31 | | | 335 | {type: 'validateChanges', userContext}, |
| b69ab31 | | | 336 | ActionTriggerType.ISL2SmartActions, |
| b69ab31 | | | 337 | ); |
| b69ab31 | | | 338 | break; |
| b69ab31 | | | 339 | } |
| b69ab31 | | | 340 | case 'platform/resolveAllConflictsWithAI': { |
| b69ab31 | | | 341 | const {conflicts, userContext} = message; |
| b69ab31 | | | 342 | Internal.promptAIAgent?.( |
| b69ab31 | | | 343 | {type: 'resolveAllConflicts', conflicts, repository: repo, context: ctx, userContext}, |
| b69ab31 | | | 344 | ActionTriggerType.ISL2MergeConflictView, |
| b69ab31 | | | 345 | ); |
| b69ab31 | | | 346 | break; |
| b69ab31 | | | 347 | } |
| b69ab31 | | | 348 | case 'platform/runAICodeReviewPlatform': { |
| b69ab31 | | | 349 | const {cwd} = message; |
| b69ab31 | | | 350 | try { |
| b69ab31 | | | 351 | const results = await Internal.runAICodeReview?.(cwd); |
| b69ab31 | | | 352 | if (results != null) { |
| b69ab31 | | | 353 | const aiReviewCommentGroup = Internal.aiReviewCommentGroup?.(); |
| b69ab31 | | | 354 | if (aiReviewCommentGroup == null) { |
| b69ab31 | | | 355 | break; |
| b69ab31 | | | 356 | } |
| b69ab31 | | | 357 | aiReviewCommentGroup.clearComments(); |
| b69ab31 | | | 358 | for (const comment of [...results.values()].flat()) { |
| b69ab31 | | | 359 | aiReviewCommentGroup.addComment( |
| b69ab31 | | | 360 | comment.filepath, |
| b69ab31 | | | 361 | comment.startLine, |
| b69ab31 | | | 362 | comment.description, |
| b69ab31 | | | 363 | ); |
| b69ab31 | | | 364 | } |
| b69ab31 | | | 365 | } |
| b69ab31 | | | 366 | } catch (err) { |
| b69ab31 | | | 367 | postMessage({ |
| b69ab31 | | | 368 | type: 'platform/gotAIReviewComments', |
| b69ab31 | | | 369 | comments: { |
| b69ab31 | | | 370 | error: err as Error, |
| b69ab31 | | | 371 | }, |
| b69ab31 | | | 372 | }); |
| b69ab31 | | | 373 | } |
| b69ab31 | | | 374 | break; |
| b69ab31 | | | 375 | } |
| b69ab31 | | | 376 | case 'platform/runAICodeReviewChat': { |
| b69ab31 | | | 377 | const {source, reviewScope, userContext} = message; |
| b69ab31 | | | 378 | await Internal.promptAIAgent?.( |
| b69ab31 | | | 379 | {type: 'reviewCode', repoPath: repo?.info.repoRoot, reviewScope, userContext}, |
| b69ab31 | | | 380 | source === 'commitInfoView' |
| b69ab31 | | | 381 | ? ActionTriggerType.ISL2CommitInfoView |
| b69ab31 | | | 382 | : ActionTriggerType.ISL2SmartActions, |
| b69ab31 | | | 383 | ); |
| b69ab31 | | | 384 | break; |
| b69ab31 | | | 385 | } |
| b69ab31 | | | 386 | case 'platform/subscribeToAIReviewComments': { |
| b69ab31 | | | 387 | const aiReviewCommentGroup = Internal.aiReviewCommentGroup?.(); |
| b69ab31 | | | 388 | if (aiReviewCommentGroup == null) { |
| b69ab31 | | | 389 | break; |
| b69ab31 | | | 390 | } |
| b69ab31 | | | 391 | aiReviewCommentGroup.onDidChangeComments( |
| b69ab31 | | | 392 | // Avoids importing FB-specific type |
| b69ab31 | | | 393 | // TODO: Should we just import the type? |
| b69ab31 | | | 394 | ( |
| b69ab31 | | | 395 | comments: { |
| b69ab31 | | | 396 | comment: { |
| b69ab31 | | | 397 | id: string; |
| b69ab31 | | | 398 | filename: string; |
| b69ab31 | | | 399 | line: number; |
| b69ab31 | | | 400 | html: string; |
| b69ab31 | | | 401 | }; |
| b69ab31 | | | 402 | }[], |
| b69ab31 | | | 403 | ) => { |
| b69ab31 | | | 404 | postMessage({ |
| b69ab31 | | | 405 | type: 'platform/gotAIReviewComments', |
| b69ab31 | | | 406 | comments: { |
| b69ab31 | | | 407 | value: comments.map( |
| b69ab31 | | | 408 | (comment): CodeReviewIssue => ({ |
| b69ab31 | | | 409 | issueID: comment.comment.id, |
| b69ab31 | | | 410 | filepath: comment.comment.filename, |
| b69ab31 | | | 411 | startLine: comment.comment.line, |
| b69ab31 | | | 412 | endLine: comment.comment.line, // TODO: get actual end line |
| b69ab31 | | | 413 | description: comment.comment.html, |
| b69ab31 | | | 414 | severity: 'medium', // TODO: get severity from comment |
| b69ab31 | | | 415 | }), |
| b69ab31 | | | 416 | ), |
| b69ab31 | | | 417 | }, |
| b69ab31 | | | 418 | }); |
| b69ab31 | | | 419 | }, |
| b69ab31 | | | 420 | ); |
| b69ab31 | | | 421 | break; |
| b69ab31 | | | 422 | } |
| b69ab31 | | | 423 | } |
| b69ab31 | | | 424 | } catch (err) { |
| b69ab31 | | | 425 | vscode.window.showErrorMessage(`error handling message ${JSON.stringify(message)}\n${err}`); |
| b69ab31 | | | 426 | } |
| b69ab31 | | | 427 | }, |
| b69ab31 | | | 428 | }); |
| b69ab31 | | | 429 | |
| b69ab31 | | | 430 | function getUnsavedFiles(repo: Repository): Array<vscode.TextDocument> { |
| b69ab31 | | | 431 | return vscode.workspace.textDocuments.filter( |
| b69ab31 | | | 432 | document => document.isDirty && repo.isPathInsideRepo(document.fileName), |
| b69ab31 | | | 433 | ); |
| b69ab31 | | | 434 | } |