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
-->
|
||
|---|---|---|
| .aspect | ||
| .buildkite | ||
| .github | ||
| .vscode | ||
| client | ||
| cmd | ||
| dev | ||
| doc | ||
| docker-images | ||
| enterprise | ||
| internal | ||
| lib | ||
| migrations | ||
| monitoring | ||
| schema | ||
| src-tauri | ||
| third_party | ||
| third-party-licenses | ||
| ui/assets | ||
| wolfi-images | ||
| wolfi-packages | ||
| .bazel_fix_commands.json | ||
| .bazelignore | ||
| .bazeliskrc | ||
| .bazelrc | ||
| .bazelversion | ||
| .browserslistrc | ||
| .dockerignore | ||
| .editorconfig | ||
| .eslintignore | ||
| .eslintrc.js | ||
| .gitattributes | ||
| .gitignore | ||
| .graphqlrc.yml | ||
| .hadolint.yaml | ||
| .mailmap | ||
| .mocharc.js | ||
| .npmrc | ||
| .percy.yml | ||
| .prettierignore | ||
| .stylelintignore | ||
| .stylelintrc.json | ||
| .tool-versions | ||
| .trivyignore | ||
| babel.config.jest.js | ||
| babel.config.js | ||
| BUILD.bazel | ||
| CHANGELOG.md | ||
| CONTRIBUTING.md | ||
| deps.bzl | ||
| doc.go | ||
| flake.lock | ||
| flake.nix | ||
| gen.go | ||
| go.mod | ||
| go.sum | ||
| graphql-schema-linter.config.js | ||
| gulpfile.js | ||
| jest.config.base.js | ||
| jest.config.js | ||
| jest.snapshot-resolver.js | ||
| LICENSE | ||
| LICENSE.apache | ||
| LICENSE.enterprise | ||
| lighthouserc.js | ||
| linter_deps.bzl | ||
| mockgen.temp.yaml | ||
| mockgen.test.yaml | ||
| mockgen.yaml | ||
| nogo_config.json | ||
| package.json | ||
| pnpm-lock.yaml | ||
| pnpm-workspace.yaml | ||
| postcss.config.js | ||
| prettier.config.js | ||
| README.md | ||
| renovate.json | ||
| SECURITY.md | ||
| service-catalog.yaml | ||
| sg.config.yaml | ||
| shell.nix | ||
| svgo.config.js | ||
| tsconfig.all.json | ||
| tsconfig.base.json | ||
| tsconfig.eslint.json | ||
| WORKSPACE | ||
Docs •
Contributing •
Twitter •
Discord
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
- Download Sourcegraph for macOS and Linux
- Use Sourcegraph on the cloud or self-hosted
- Sourcegraph.com public code search
Development
Refer to the Developing Sourcegraph guide to get started.
Documentation
The doc directory has additional documentation for developing and understanding Sourcegraph:
- Project FAQ
- Architecture: high-level architecture
- Database setup: database best practices
- Go style guide
- Documentation style guide
- GraphQL API: useful tips when modifying the GraphQL API
- Contributing
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.