Skip to content

Commit

Permalink
feat: fix vfs bug and add git projects managements settings
Browse files Browse the repository at this point in the history
  • Loading branch information
2214962083 committed Jan 16, 2025
1 parent 0f028cf commit be6fc89
Show file tree
Hide file tree
Showing 42 changed files with 1,931 additions and 129 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@
"comment-json": "^4.2.5",
"commitizen": "^4.3.1",
"cpy": "10.1.0",
"date-fns": "^4.1.0",
"diff": "^7.0.0",
"es-toolkit": "^1.31.0",
"eslint": "^8.57.0",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

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

3 changes: 2 additions & 1 deletion src/extension/actions/apply-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { HumanMessage, SystemMessage } from '@langchain/core/messages'
import { ServerActionCollection } from '@shared/actions/server-action-collection'
import type { ActionContext } from '@shared/actions/types'
import { FeatureModelSettingKey } from '@shared/entities'
import { toUnixPath } from '@shared/utils/common'
import * as vscode from 'vscode'

export class ApplyActionsCollection extends ServerActionCollection {
Expand Down Expand Up @@ -66,7 +67,7 @@ Don't reply with anything except the code.

const uri =
vscode.window.visibleTextEditors.find(
editor => editor.document.uri.fsPath === fullPath
editor => toUnixPath(editor.document.uri.fsPath) === fullPath
)?.document.uri || vscode.Uri.file(fullPath)
const document = await vscode.workspace.openTextDocument(uri)
const fullRange = new vscode.Range(
Expand Down
12 changes: 8 additions & 4 deletions src/extension/actions/file-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
type FolderInfo
} from '@extension/file-utils/traverse-fs'
import { vfs } from '@extension/file-utils/vfs'
import { workspaceSchemeHandler } from '@extension/file-utils/vfs/schemes/workspace-scheme'
import { logger } from '@extension/logger'
import { ServerActionCollection } from '@shared/actions/server-action-collection'
import type { ActionContext } from '@shared/actions/types'
Expand Down Expand Up @@ -175,8 +176,9 @@ export class FileActionsCollection extends ServerActionCollection {
const { actionParams } = context
const { schemeUris } = actionParams
const finalSchemeUris = await settledPromiseResults(
schemeUris.map(schemeUri => vfs.fixSchemeUri(schemeUri))
schemeUris.map(async schemeUri => await vfs.fixSchemeUri(schemeUri))
)

return await traverseFileOrFolders({
type: 'file',
schemeUris: finalSchemeUris,
Expand All @@ -191,7 +193,7 @@ export class FileActionsCollection extends ServerActionCollection {
const { actionParams } = context
const { schemeUris } = actionParams
const finalSchemeUris = await settledPromiseResults(
schemeUris.map(schemeUri => vfs.fixSchemeUri(schemeUri))
schemeUris.map(async schemeUri => await vfs.fixSchemeUri(schemeUri))
)
return await traverseFileOrFolders({
type: 'folder',
Expand Down Expand Up @@ -250,7 +252,9 @@ export class FileActionsCollection extends ServerActionCollection {
d.severity === vscode.DiagnosticSeverity.Error
? 'error'
: 'warning',
file: vscode.workspace.asRelativePath(document.uri),
schemeUri: workspaceSchemeHandler.createSchemeUri({
fullPath: document.uri.fsPath
}),
line: d.range.start.line + 1,
column: d.range.start.character + 1
} satisfies EditorError
Expand All @@ -266,7 +270,7 @@ export class FileActionsCollection extends ServerActionCollection {
self.findIndex(
e =>
e.message === error.message &&
e.file === error.file &&
e.schemeUri === error.schemeUri &&
e.line === error.line &&
e.column === error.column
)
Expand Down
43 changes: 22 additions & 21 deletions src/extension/actions/git-actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { CommandManager } from '@extension/commands/command-manager'
import type { RegisterManager } from '@extension/registers/register-manager'
import { gitUtils } from '@extension/file-utils/git'
import { getWorkspaceFolder } from '@extension/utils'
import { ServerActionCollection } from '@shared/actions/server-action-collection'
import type { ActionContext } from '@shared/actions/types'
Expand All @@ -8,32 +7,28 @@ import type {
GitDiff
} from '@shared/plugins/mentions/git-mention-plugin/types'
import { settledPromiseResults } from '@shared/utils/common'
import simpleGit, { SimpleGit } from 'simple-git'
import { SimpleGit } from 'simple-git'

export class GitActionsCollection extends ServerActionCollection {
readonly categoryName = 'git'

private git: SimpleGit

constructor(
registerManager: RegisterManager,
commandManager: CommandManager
) {
super(registerManager, commandManager)
private async getGit(): Promise<SimpleGit> {
const workspaceFolder = getWorkspaceFolder()
this.git = simpleGit(workspaceFolder.uri.fsPath)
const git = await gitUtils.createGit(workspaceFolder.uri.fsPath)
return git
}

async getHistoryCommits(
context: ActionContext<{ maxCount?: number }>
): Promise<GitCommit[]> {
const { actionParams } = context
const { maxCount = 50 } = actionParams
const log = await this.git.log({ maxCount })
const git = await this.getGit()
const log = await git.log({ maxCount })

const commits: GitCommit[] = await settledPromiseResults(
log.all.map(async commit => {
const diff = await this.git.diff([`${commit.hash}^`, commit.hash])
const diff = await git.diff([`${commit.hash}^`, commit.hash])
return {
sha: commit.hash,
message: commit.message,
Expand All @@ -52,13 +47,14 @@ export class GitActionsCollection extends ServerActionCollection {
): Promise<GitDiff[]> {
const { actionParams } = context
const { file } = actionParams
const git = await this.getGit()
const mainBranchName = await this.getMainBranchName()
let diff: string

if (file) {
diff = await this.git.diff([`origin/${mainBranchName}`, '--', file])
diff = await git.diff([`origin/${mainBranchName}`, '--', file])
} else {
diff = await this.git.diff([`origin/${mainBranchName}`])
diff = await git.diff([`origin/${mainBranchName}`])
}

return this.parseDiff(diff)
Expand All @@ -69,12 +65,13 @@ export class GitActionsCollection extends ServerActionCollection {
): Promise<GitDiff[]> {
const { actionParams } = context
const { file } = actionParams
const git = await this.getGit()
let diff: string

if (file) {
diff = await this.git.diff(['HEAD', '--', file])
diff = await git.diff(['HEAD', '--', file])
} else {
diff = await this.git.diff(['HEAD'])
diff = await git.diff(['HEAD'])
}

return this.parseDiff(diff)
Expand Down Expand Up @@ -110,20 +107,24 @@ export class GitActionsCollection extends ServerActionCollection {
}

async getCurrentBranch(context: ActionContext<{}>): Promise<string> {
return await this.git.revparse(['--abbrev-ref', 'HEAD'])
const git = await this.getGit()
return await git.revparse(['--abbrev-ref', 'HEAD'])
}

async getStatus(context: ActionContext<{}>): Promise<any> {
return await this.git.status()
const git = await this.getGit()
return await git.status()
}

async getRemotes(context: ActionContext<{}>): Promise<any[]> {
const remotes = await this.git.getRemotes(true)
const git = await this.getGit()
const remotes = await git.getRemotes(true)
return remotes
}

private async getMainBranchName(): Promise<string> {
const branches = await this.git.branch()
const git = await this.getGit()
const branches = await git.branch()
const mainBranch = ['main', 'master', 'trunk', 'development'].find(branch =>
branches.all.includes(branch)
)
Expand Down
Loading

0 comments on commit be6fc89

Please sign in to comment.