Code AI platform with Code Search & Cody
Go to file
Philipp Spiess f5b0668415
Cody: Add a cache for inline completions (#51046)
This adds a simple LRU cache for completions with the main goal to
further reduce the number of requests and reduce annoying churn in the
scenario where a user receives a completion and types the exact same
characters. Previously, the new characters would cause a new completion
request which could yield different result.

Here's an example of how this cache works:

- Imagine the current file prefix looks like this with the cursor at the
end:
    ```ts
    const files = ["a", "b"];
    for(let i = 0;
    ```
- We receive the following completion:
   - ` i < files.length; i++) {`
- We now generate create different versions (up until the next `\n`) of
the input prefix by concatenating characters from the completion (Only
using the last line here to visualize):
   1. `for(let i = 0;`
   2. `for(let i = 0; `
   3. `for(let i = 0; i`
   4. `for(let i = 0; i `
   5. `for(let i = 0; i <`
   6. `for(let i = 0; i < `
   7. `for(let i = 0; i < f`
   8. `for(let i = 0; i < fi`
   9. `for(let i = 0; i < fil`
   10. `for(let i = 0; i < file`
   11. ...

## Additional thoughts

- I have't added a cache to multiline providers, since these are
triggered less often than inline suggestions anyways.
- The LRU cache is limited to 500 file prefixes, regardless of how large
these are. We might want to tweak this later. It also currently retain
the `prompt` as part of the `Completion` interface which may not be
necessary.
- I've re-enabled the request that forces adds a `\n` to the prefix.
These can now be reused if you type enter and will result in a faster
suggestion for the next line.

## Test plan

I've added a `console.log` when a cache hit is encountered to visualize
it while playing around with it:



https://user-images.githubusercontent.com/458591/234050774-2215a146-904d-47ae-b82e-c90ef131fe3e.mov


<!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
-->
2023-04-25 10:46:08 +02:00
.aspect bazel: remove disk/remote cache settings (#50814) 2023-04-18 16:03:19 +00:00
.buildkite Remove tracing and associated plumbing (#51001) 2023-04-21 20:44:40 +02:00
.github batches: update pings for batches notify (#51053) 2023-04-24 13:11:04 -07:00
.vscode focus cody chat on startup when launching debug task from vscode (#50685) 2023-04-15 20:48:36 -07:00
client Cody: Add a cache for inline completions (#51046) 2023-04-25 10:46:08 +02:00
cmd test: use t.Setenv to set env vars (#48669) 2023-04-25 10:24:56 +02:00
dev (chore) rename repo key-value-pairs to repo metadata on the API level (#50908) 2023-04-24 20:38:16 +06:00
doc Update embedded-repos.md (#51064) 2023-04-24 19:31:33 -05:00
docker-images Build Wolfi images (#47182) 2023-04-24 17:32:36 +00:00
enterprise Embeddings: fix unmarshaling old version of index (#51070) 2023-04-24 23:46:32 -03:00
internal test: use t.Setenv to set env vars (#48669) 2023-04-25 10:24:56 +02:00
lib bazel: add depguard as a nogo linter (#50585) 2023-04-13 14:19:45 +02:00
migrations own: basic auto-indexing for background signal calculations (#50951) 2023-04-24 14:15:19 -07:00
monitoring own: basic auto-indexing for background signal calculations (#50951) 2023-04-24 14:15:19 -07:00
schema own: basic auto-indexing for background signal calculations (#50951) 2023-04-24 14:15:19 -07:00
src-tauri App: Don't require sourcegraph binary to embed for sg start app (#51058) 2023-04-24 15:31:37 -04:00
third_party bazel: update buildfiles (#47744) 2023-02-16 16:32:59 +01:00
third-party-licenses chore: update third-party licenses (#51023) 2023-04-24 07:11:24 +02:00
ui/assets Revert docker bazel frontend (#50326) 2023-04-04 10:24:05 +00:00
wolfi-images Build Wolfi images (#47182) 2023-04-24 17:32:36 +00:00
wolfi-packages Build Wolfi images (#47182) 2023-04-24 17:32:36 +00:00
.bazel_fix_commands.json bazel: add command sets that uses bazel under the hood (#48460) 2023-03-02 11:31:51 +01:00
.bazelignore app: improve bundling of app-shell code (#51038) 2023-04-24 16:57:51 +00:00
.bazeliskrc chore: update to Aspect CLI 5.2.1 (#48798) 2023-03-07 10:13:33 +01:00
.bazelrc bazel: client e2e tests (#50330) 2023-04-13 04:01:37 -07:00
.bazelversion Update bazel to 6.1.1 (#50472) 2023-04-11 10:51:21 +02:00
.browserslistrc web: migrate from yarn to pnpm (#46143) 2023-01-11 19:50:09 -08:00
.dockerignore web: migrate from yarn to pnpm (#46143) 2023-01-11 19:50:09 -08:00
.editorconfig chore: Add .lua to editorconfig. (#44267) 2022-11-11 15:25:32 +08:00
.eslintignore [experiment] Merge SvelteKit prototype into main (#47238) 2023-02-13 17:53:23 +01:00
.eslintrc.js Better import ordering with prettier (#48188) 2023-03-13 08:37:23 +00:00
.gitattributes bazel: Build syntax-highlighter (#48703) 2023-03-08 19:08:09 +08:00
.gitignore Port back compat tests to Bazel (#50932) 2023-04-21 14:39:36 +02:00
.graphqlrc.yml Support multiple GraphQL schema files (#20077) 2021-04-19 14:35:49 +02:00
.hadolint.yaml bump comby version to 1.7.1 (#35830) 2022-05-20 20:12:01 -07:00
.mailmap mailmap: add entries for Eric and Renovate (#50966) 2023-04-25 09:42:22 +02:00
.mocharc.js build: still need BAZEL_BINDIR for webpack_bundle custom rule (#48796) 2023-03-07 20:02:11 -08:00
.npmrc web: fix pnpm-lock issue (#47478) 2023-02-09 22:04:31 -08:00
.percy.yml Update browser extention installation detection logic on web (#32449) 2022-03-14 23:29:39 +06:00
.prettierignore app: experimental Tauri branch (#50620) 2023-04-21 19:48:47 +02:00
.stylelintignore rework plugin structure and implement frontside blogpost (#46883) 2023-02-15 11:49:51 +02:00
.stylelintrc.json web: drop bootstrap depenedency (#41401) 2022-09-07 03:11:26 -07:00
.tool-versions Update to go 1.19.8 (#50341) 2023-04-05 17:39:02 +02:00
.trivyignore ci: ignore benign CVE-2021-43816 in prometheus (#31069) 2022-02-11 16:49:10 +00:00
babel.config.jest.js bazel: fix the web application bundle in Bazel (#50383) 2023-04-10 21:16:12 -07:00
babel.config.js bazel: fix the web application bundle in Bazel (#50383) 2023-04-10 21:16:12 -07:00
BUILD.bazel bazel: add unparam nogo linter (#50730) 2023-04-18 10:03:35 +00:00
CHANGELOG.md chore: modify changelog with link to the bitbucket server logs fix (#51034) 2023-04-24 12:39:08 +02:00
CONTRIBUTING.md Docs: Fix docs page link in main CONTRIBUTING.md (#45160) 2022-12-05 14:57:45 +01:00
deps.bzl Embeddings: exclude files by size in embedFiles (#51021) 2023-04-24 17:39:51 -06:00
doc.go
flake.lock nix: update to get latest go1.20.3 (#50639) 2023-04-18 08:49:55 +02:00
flake.nix nix: use go1.20 (#47541) 2023-02-13 12:19:12 +02:00
gen.go chore: Update go-mockgen (#44305) 2022-11-11 19:24:00 +00:00
go.mod dep: update crewjam to latest (#51040) 2023-04-25 10:04:33 +02:00
go.sum dep: update crewjam to latest (#51040) 2023-04-25 10:04:33 +02:00
graphql-schema-linter.config.js Support multiple GraphQL schema files (#20077) 2021-04-19 14:35:49 +02:00
gulpfile.js web: drop legacy GraphQL schema generator (#45945) 2022-12-25 18:10:20 -08:00
jest.config.base.js bazel: wildcard jest tests (#49282) 2023-03-17 03:38:49 -07:00
jest.config.js tests: use glob for jest projects field (#29681) 2022-01-13 01:11:52 -08:00
jest.snapshot-resolver.js bazel: wildcard jest tests (#49282) 2023-03-17 03:38:49 -07:00
LICENSE update licensing language (#25620) 2021-10-04 15:40:59 +01:00
LICENSE.apache
LICENSE.enterprise
lighthouserc.js web: migrate from yarn to pnpm (#46143) 2023-01-11 19:50:09 -08:00
linter_deps.bzl bazel: add unparam nogo linter (#50730) 2023-04-18 10:03:35 +00:00
mockgen.temp.yaml [github app] Add GitHub App authenticators (#50963) 2023-04-24 09:05:50 +02:00
mockgen.test.yaml [language-platform] Remove unnecessary dependencies in upload service (#50870) 2023-04-24 09:56:47 -06:00
mockgen.yaml mocks: Reorganize mock definitions into multiple files (#36967) 2022-06-27 20:59:16 +00:00
nogo_config.json bazel: add depguard as a nogo linter (#50585) 2023-04-13 14:19:45 +02:00
package.json app: improve bundling of app-shell code (#51038) 2023-04-24 16:57:51 +00:00
pnpm-lock.yaml Cody: Add a cache for inline completions (#51046) 2023-04-25 10:46:08 +02:00
pnpm-workspace.yaml cody: development branch (#49761) 2023-03-23 20:41:11 +01:00
postcss.config.js extensibility: add featured extensions to registry (#21665) 2021-06-10 13:55:20 -04:00
prettier.config.js clean up Cody CSS to increase shareability and improve display in web app (#50279) 2023-04-03 12:29:05 -07:00
README.md update readme and docs index for 5.0 (#49988) 2023-03-24 21:48:46 -06:00
renovate.json chore: add test plans to bot and release tool PRs (#31351) 2022-02-22 07:53:25 -08:00
SECURITY.md
service-catalog.yaml lib/servicecatalog: init to distribute catalog (#46999) 2023-01-26 17:22:27 -08:00
sg.config.yaml App: Don't require sourcegraph binary to embed for sg start app (#51058) 2023-04-24 15:31:37 -04:00
shell.nix nix: add bazel-watcher (#50956) 2023-04-21 13:14:35 +02:00
svgo.config.js Performance: Optimize static SVG assets with SVGO (#26285) 2021-10-27 15:27:36 +01:00
tsconfig.all.json unskip cody integration test & add another (#51019) 2023-04-23 22:19:16 -07:00
tsconfig.base.json web: fix pnpm-lock issue (#47478) 2023-02-09 22:04:31 -08:00
tsconfig.eslint.json web: fix pnpm-lock issue (#47478) 2023-02-09 22:04:31 -08:00
WORKSPACE Embeddings: exclude files by size in embedFiles (#51021) 2023-04-24 17:39:51 -06:00

DocsContributingTwitterDiscord

Build status Scorecard Latest release Discord Contributors


Sourcegraph makes it easy to read, write, and fix code—even in big, complex codebases.

  • Code search: Search all of your repositories across all branches and all code hosts.
  • Code intelligence: Navigate code, find references, see code owners, trace history, and more.
  • Fix and refactor: Roll out large-scale changes to many repositories at once and track big migrations.

Getting started



Development

Refer to the Developing Sourcegraph guide to get started.

Documentation

The doc directory has additional documentation for developing and understanding Sourcegraph:

License

This repository contains both OSS-licensed and non-OSS-licensed files. We maintain one repository rather than two separate repositories mainly for development convenience.

All files in the enterprise and client/web/src/enterprise fall under LICENSE.enterprise.

The remaining files fall under the Apache 2 license. Sourcegraph OSS is built only from the Apache-licensed files in this repository.