Skip to content

Commit

Permalink
fix: fix project info framework detection
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Jul 15, 2023
1 parent 6a142a4 commit cfcb171
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
5 changes: 0 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { addOrRemoveCurrentDocument } from './commands/addOrRemoveCurrentDocumen
import { sendCurrentDocument } from './commands/sendCurrentDocumentOrStack'
import { server } from './libs/server'
import { stateManager } from './libs/stateManager'
import { getCurrentWorkspaceInfo } from './utils/getCurrentWorkspaceInfo'
import { handleError } from './utils/handleError'
import { updateStackStatusBarItem } from './utils/updateStackStatusBarItem'
import { updateStateStatusBarItem } from './utils/updateStateStatusBarItem'
Expand Down Expand Up @@ -42,10 +41,6 @@ export async function activate(context: ExtensionContext) {
// WebSocket Server

server.start()

const workspaceInfo = await getCurrentWorkspaceInfo()

console.log(JSON.stringify(workspaceInfo, null, 2))
} catch (err) {
handleError(err)

Expand Down
2 changes: 1 addition & 1 deletion src/utils/getCurrentWorkspaceInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function getCurrentWorkspaceInfo(mustRefresh: boolean = false): Pro
throw new UserError("OpenAI Forge couldn't detect any of the supported languages for this workspace.")
}

const frameworks = await getProjectFrameworks(rootPath)
const frameworks = await getProjectFrameworks(rootPath, sourceCodeDocumentPaths)

const sourceCodeDocumentsLength = sourceCodeDocumentPaths.length

Expand Down
17 changes: 11 additions & 6 deletions src/utils/getProjectFrameworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { ProjectFramework } from '../types'
// Each criteria is a function that takes a list of paths and returns a boolean.
type ProjectFrameworkMatcher = (paths: string[]) => boolean

const isReactProject: ProjectFrameworkMatcher = any<string>(path => /.*\.(j|t)sx$/.test(path))
const isNextProject: ProjectFrameworkMatcher = any<string>(path => /.*(^|\/).next\/.*/.test(path))
const isTauriProject: ProjectFrameworkMatcher = any<string>(path => /.*(^|\/)src-tauri\/.*/.test(path))
const isReactProject: ProjectFrameworkMatcher = any<string>(path => /\.(j|t)sx$/.test(path))
const isNextProject: ProjectFrameworkMatcher = any<string>(path => /(^|\/).next(\/|$)/.test(path))
const isTauriProject: ProjectFrameworkMatcher = any<string>(path => /(^|\/)src-tauri(\/|$)/.test(path))

// A map of ProjectFrameworks to their corresponding criteria.
const PROJECT_FRAMEWORK_MATCHER_MATCH: Record<ProjectFramework, ProjectFrameworkMatcher> = {
Expand All @@ -17,11 +17,16 @@ const PROJECT_FRAMEWORK_MATCHER_MATCH: Record<ProjectFramework, ProjectFramework
[ProjectFramework.TAURI]: isTauriProject,
}

export async function getProjectFrameworks(workspacePath: string): Promise<ProjectFramework[]> {
const rootFiles = await fs.readdir(workspacePath)
export async function getProjectFrameworks(
workspacePath: string,
sourceCodeDocumentPaths: string[],
): Promise<ProjectFramework[]> {
const rootPaths = await fs.readdir(workspacePath)
const sourceCodeDocumentRelativePaths = sourceCodeDocumentPaths.map(path => path.replace(`${workspacePath}/`, ''))
const allPaths = [...rootPaths, ...sourceCodeDocumentRelativePaths]

const projectFrameworks = filter(
(framework: ProjectFramework) => PROJECT_FRAMEWORK_MATCHER_MATCH[framework](rootFiles),
(framework: ProjectFramework) => PROJECT_FRAMEWORK_MATCHER_MATCH[framework](allPaths),
keys(PROJECT_FRAMEWORK_MATCHER_MATCH),
)

Expand Down

0 comments on commit cfcb171

Please sign in to comment.