Skip to content

Commit

Permalink
Improve 'needs README' context detection (#4471)
Browse files Browse the repository at this point in the history
This is a tiny fix to our `needsReadmeContext` detection. Previously, we split
the question on punctuation, but did not do the same for the root directory
name. So we would never match if the repo contained a hyphen, etc.
  • Loading branch information
jtibshirani authored Jun 6, 2024
1 parent 88a0cfb commit 6e46194
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions vscode/src/chat/chat-view/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,35 +391,30 @@ function needsReadmeContext(editor: VSCodeEditor, input: PromptString): boolean
const words = stringInput.split(/\W+/).filter(w => w.length > 0)
const bagOfWords = Object.fromEntries(words.map(w => [w, true]))

const projectSignifiers = [
'project',
'repository',
'repo',
'library',
'package',
'module',
'codebase',
]
const questionIndicators = ['what', 'how', 'describe', 'explain', '?']

const workspaceUri = editor.getWorkspaceRootUri()
if (workspaceUri) {
const rootBase = workspaceUri.toString().split('/').at(-1)
if (rootBase) {
projectSignifiers.push(rootBase.toLowerCase())
}
}

let containsProjectSignifier = false
for (const p of projectSignifiers) {
if (bagOfWords[p]) {
containsProjectSignifier = true
break
const workspaceName = vscode.workspace.workspaceFolders?.[0]?.name
if (workspaceName && stringInput.includes('@' + workspaceName)) {
containsProjectSignifier = true
} else {
const projectSignifiers = [
'project',
'repository',
'repo',
'library',
'package',
'module',
'codebase',
]
for (const p of projectSignifiers) {
if (bagOfWords[p]) {
containsProjectSignifier = true
break
}
}
}

let containsQuestionIndicator = false
for (const q of questionIndicators) {
for (const q of ['what', 'how', 'describe', 'explain']) {
if (bagOfWords[q]) {
containsQuestionIndicator = true
break
Expand Down

0 comments on commit 6e46194

Please sign in to comment.