Skip to content

Commit

Permalink
Merge branch 'main' into dallin/gui-strict-null-checks
Browse files Browse the repository at this point in the history
  • Loading branch information
sestinj committed Nov 27, 2024
2 parents 2ce8f70 + b2f12ac commit 591497a
Show file tree
Hide file tree
Showing 43 changed files with 4,114 additions and 399 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/submit-github-dependency-graph.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Submit Gradle Dependency Graph For Dependabot

on:
push:
branches: ['main']

permissions:
contents: write

jobs:
dependency-submission:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@v4
with:
# The gradle project is not in the root of the repository.
build-root-directory: extensions/intellij
2 changes: 1 addition & 1 deletion core/autocomplete/CompletionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export class CompletionProvider {
//////////

// Save to cache
if (!outcome.cacheHit) {
if (!outcome.cacheHit && helper.options.useCache) {
(await this.autocompleteCache).put(outcome.prefix, outcome.completion);

Check warning on line 256 in core/autocomplete/CompletionProvider.ts

View workflow job for this annotation

GitHub Actions / tsc-check

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}

Expand Down
2 changes: 1 addition & 1 deletion core/autocomplete/snippets/getAllSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const getDiffSnippets = async (
): Promise<AutocompleteDiffSnippet[]> => {
const diff = await ide.getDiff(true);

return [diff].map((item) => {
return diff.map((item) => {
return {
content: item,
type: AutocompleteSnippetType.Diff,
Expand Down
21 changes: 14 additions & 7 deletions core/autocomplete/templating/AutocompleteTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,32 @@ const codestralMultifileFimTemplate: AutocompleteTemplate = {
suffix: string,
filepath: string,
reponame: string,
allSnippets: AutocompleteSnippet[],
snippets: AutocompleteSnippet[],
): [string, string] => {
const snippets = allSnippets.filter(
(snippet) => snippet.type === AutocompleteSnippetType.Code,
) as AutocompleteCodeSnippet[];

if (snippets.length === 0) {
if (suffix.trim().length === 0 && prefix.trim().length === 0) {
return [`+++++ ${getLastNPathParts(filepath, 2)}\n${prefix}`, suffix];
}
return [prefix, suffix];
}

const relativePaths = shortestRelativePaths([
...snippets.map((snippet) => snippet.filepath),
...snippets.map((snippet) =>
"filepath" in snippet ? snippet.filepath : "Untitled.txt",
),
filepath,
]);

const otherFiles = snippets
.map((snippet, i) => `+++++ ${relativePaths[i]}\n${snippet.content}`)
.map((snippet, i) => {
if (snippet.type === AutocompleteSnippetType.Diff) {
return snippet.content;
}

return `+++++ ${relativePaths[i]}\n${snippet.content}`;
})
.join("\n\n");

return [
`${otherFiles}\n\n+++++ ${
relativePaths[relativePaths.length - 1]
Expand Down
2 changes: 1 addition & 1 deletion core/autocomplete/templating/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const formatSnippets = (
return item.content + `\n${commentMark}\n${commentMark}`;
}

return item.content + "\n\n";
return item.content;
})
.join("\n") + `\n${currentFilepathComment}`
);
Expand Down
11 changes: 6 additions & 5 deletions core/commands/slash/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ const CommitMessageCommand: SlashCommand = {
const includeUnstaged = params?.includeUnstaged ?? false;
const diff = await ide.getDiff(includeUnstaged);

if (!diff || diff.trim() === "") {
if (diff.length === 0) {
yield "No changes detected. Make sure you are in a git repository with current changes.";
return;
}

const prompt = `${diff}\n\nGenerate a commit message for the above set of changes. First, give a single sentence, no more than 80 characters. Then, after 2 line breaks, give a list of no more than 5 short bullet points, each no more than 40 characters. Output nothing except for the commit message, and don't surround it in quotes.`;
for await (const chunk of llm.streamChat([
{ role: "user", content: prompt },
], new AbortController().signal)) {
const prompt = `${diff.join("\n")}\n\nGenerate a commit message for the above set of changes. First, give a single sentence, no more than 80 characters. Then, after 2 line breaks, give a list of no more than 5 short bullet points, each no more than 40 characters. Output nothing except for the commit message, and don't surround it in quotes.`;
for await (const chunk of llm.streamChat(
[{ role: "user", content: prompt }],
new AbortController().signal,
)) {
yield stripImages(chunk.content);
}
},
Expand Down
7 changes: 5 additions & 2 deletions core/config/promptFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ export function slashCommandFromPromptFile(
systemMessage,
);

for await (const chunk of context.llm.streamChat(messages, new AbortController().signal)) {
for await (const chunk of context.llm.streamChat(
messages,
new AbortController().signal,
)) {
yield stripImages(chunk.content);
}

Expand Down Expand Up @@ -173,7 +176,7 @@ async function renderPrompt(
const diff = await context.ide.getDiff(false);
const currentFile = await context.ide.getCurrentFile();
const inputData: Record<string, string> = {
diff,
diff: diff.join("\n"),
input: userInput,
};
if (currentFile) {
Expand Down
4 changes: 2 additions & 2 deletions core/context/providers/DiffContextProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class DiffContextProvider extends BaseContextProvider {
{
description: "The current git diff",
content:
diff.trim() === ""
diff.length === 0
? "Git shows no current changes."
: `\`\`\`git diff\n${diff}\n\`\`\``,
: `\`\`\`git diff\n${diff.join("\n")}\n\`\`\``,
name: "Git Diff",
},
];
Expand Down
10 changes: 10 additions & 0 deletions core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,16 @@ export class Core {
if (config.experimental?.readResponseTTS && "completion" in next.value) {
void TTS.read(next.value?.completion);
}

void Telemetry.capture(
"chat",
{
model: model.model,
provider: model.providerName,
},
true,
);

return { done: true, content: next.value };
}

Expand Down
2 changes: 1 addition & 1 deletion core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ export interface IdeSettings {
export interface IDE {
getIdeInfo(): Promise<IdeInfo>;
getIdeSettings(): Promise<IdeSettings>;
getDiff(includeUnstaged: boolean): Promise<string>;
getDiff(includeUnstaged: boolean): Promise<string[]>;
getClipboardContent(): Promise<{ text: string; copiedAt: string }>;
isTelemetryEnabled(): Promise<boolean>;
getUniqueId(): Promise<string>;
Expand Down
13 changes: 5 additions & 8 deletions core/llm/llms/OpenAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class OpenAI extends BaseLLM {
text: part.text,
};
if (part.type === "imageUrl") {
msg.image_url = { ...part.imageUrl, detail: "low" };
msg.image_url = { ...part.imageUrl, detail: "auto" };
msg.type = "image_url";
}
return msg;
Expand Down Expand Up @@ -130,10 +130,7 @@ class OpenAI extends BaseLLM {
finalOptions.max_completion_tokens = options.maxTokens;
finalOptions.max_tokens = undefined;

// b) don't support streaming currently
finalOptions.stream = false;

// c) don't support system message
// b) don't support system message
finalOptions.messages = finalOptions.messages?.filter(
(message: any) => message?.role !== "system",
);
Expand Down Expand Up @@ -229,7 +226,7 @@ class OpenAI extends BaseLLM {
...args,
stream: true,
}),
signal
signal,
});

for await (const value of streamSse(response)) {
Expand Down Expand Up @@ -274,7 +271,7 @@ class OpenAI extends BaseLLM {
method: "POST",
headers: this._getHeaders(),
body: JSON.stringify(body),
signal
signal,
});

// Handle non-streaming response
Expand Down Expand Up @@ -318,7 +315,7 @@ class OpenAI extends BaseLLM {
"x-api-key": this.apiKey ?? "",
Authorization: `Bearer ${this.apiKey}`,
},
signal
signal,
});
for await (const chunk of streamSse(resp)) {
yield chunk.choices[0].delta.content;
Expand Down
2 changes: 1 addition & 1 deletion core/protocol/ide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export type ToIdeFromWebviewOrCoreProtocol = {
getPinnedFiles: [undefined, string[]];
showLines: [{ filepath: string; startLine: number; endLine: number }, void];
readRangeInFile: [{ filepath: string; range: Range }, string];
getDiff: [{ includeUnstaged: boolean }, string];
getDiff: [{ includeUnstaged: boolean }, string[]];
getWorkspaceConfigs: [undefined, ContinueRcJson[]];
getTerminalContents: [undefined, string];
getDebugLocals: [{ threadIndex: number }, string];
Expand Down
4 changes: 2 additions & 2 deletions core/util/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ class FileSystemIde implements IDE {
return Promise.resolve([]);
}

getDiff(includeUnstaged: boolean): Promise<string> {
return Promise.resolve("");
getDiff(includeUnstaged: boolean): Promise<string[]> {
return Promise.resolve([]);
}

getClipboardContent(): Promise<{ text: string; copiedAt: string }> {
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/chat/context-selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The highlighted code you’ve selected by pressing <kbd>cmd/ctrl</kbd> + <kbd>L<

## Active file

You can include the currently open file as context by pressing <kbd>cmd/ctrl</kbd> + <kbd>opt</kbd> + <kbd>enter</kbd> when you send your request.
You can include the currently open file as context by pressing <kbd>cmd</kbd> + <kbd>opt</kbd> + <kbd>enter</kbd> (Mac) or <kbd>ctrl</kbd> + <kbd>alt</kbd> + <kbd>enter</kbd> (Windows) when you send your request.

## Specific file

Expand Down
3 changes: 1 addition & 2 deletions extensions/vscode/src/VsCodeIde.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import type {
RangeInFile,
Thread,
} from "core";
import { text } from "stream/consumers";

class VsCodeIde implements IDE {
ideUtils: VsCodeIdeUtils;
Expand Down Expand Up @@ -312,7 +311,7 @@ class VsCodeIde implements IDE {
return Promise.resolve(vscode.env.machineId);
}

async getDiff(includeUnstaged: boolean): Promise<string> {
async getDiff(includeUnstaged: boolean): Promise<string[]> {
return await this.ideUtils.getDiff(includeUnstaged);
}

Expand Down
2 changes: 1 addition & 1 deletion extensions/vscode/src/test/test-suites/ideUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("IDE Utils", () => {

test("noDiff", async () => {
const noDiff = await utils.getDiff(false);
assert(noDiff === "");
assert(noDiff.length === 0);
});

test.skip("getBranch", async () => {
Expand Down
20 changes: 15 additions & 5 deletions extensions/vscode/src/util/ideUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,20 @@ export class VsCodeIdeUtils {
return repo?.state?.HEAD?.name || "NONE";
}

async getDiff(includeUnstaged: boolean): Promise<string> {
let diffs: string[] = [];
private splitDiff(diffString: string): string[] {
const fileDiffHeaderRegex = /(?=diff --git a\/.* b\/.*)/;

const diffs = diffString.split(fileDiffHeaderRegex);

if (diffs[0].trim() === "") {
diffs.shift();
}

return diffs;
}

async getDiff(includeUnstaged: boolean): Promise<string[]> {
const diffs: string[] = [];

for (const dir of this.getWorkspaceDirectories()) {
const repo = await this.getRepo(vscode.Uri.file(dir));
Expand All @@ -587,9 +599,7 @@ export class VsCodeIdeUtils {
}
}

const fullDiff = diffs.join("\n\n");

return fullDiff;
return diffs.flatMap((diff) => this.splitDiff(diff));
}

getHighlightedCode(): RangeInFile[] {
Expand Down
32 changes: 32 additions & 0 deletions gui/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"strict-null-checks",
"eslint-plugin-react"
],
"parserOptions": {
"project": "gui/tsconfig.strictNullChecks.json"
},
// "extends": [
// "eslint:recommended",
// "plugin:@typescript-eslint/recommended",
// "plugin:@typescript-eslint/recommended-requiring-type-checking"
// "plugin:react/recommended"
// ],
"rules": {
"strict-null-checks/all": "warn"
},
"overrides": [
{
"files": ["src/**/*.{js,ts,jsx,tsx}"]
}
],
"ignorePatterns": ["dist/**/*"],
"env": {
"browser": true,
"node": true,
"es6": true
}
}
Loading

0 comments on commit 591497a

Please sign in to comment.