Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

fix(svelte): Respect cody ignore settings#63677

Merged
fkling merged 4 commits into
mainfrom
fkling-srch-692-respect-cody-ignore-feature
Jul 9, 2024
Merged

fix(svelte): Respect cody ignore settings#63677
fkling merged 4 commits into
mainfrom
fkling-srch-692-respect-cody-ignore-feature

Conversation

@fkling

@fkling fkling commented Jul 5, 2024

Copy link
Copy Markdown
Contributor

This commit adds support for cody ignore settings to the SvelteKit app. When cody is disabled on the instance or for the user, the cody button and sidebar are not shown anymore.

Likewise if the repository is excluded from cody, the buttons and sidebar are not shown.

The implementation was inspired by useCodyIngore.ts, but simplified for use in the SvelteKit app. It seems that the file exclusion logic is not actually used for the sidebar and thus was omitted. It also seems that for the sidebar itself we are only checking whether the current repository is excluded or not, which lets us simplify the whole setup and simply pass a boolean (store) from the data loader, indicating whether cody is enabled or not.

Furthermore I introduced zod to validate that the value of codyContextFilters.raw, which is typed as JSONValue, has the expected shape. We've run into issues in the past where such values have just been cast to the expected Typescript type. zod adds runtime validation.

Note that we use JSON schema base validation (with ajv) in some places, but that requires importing and sending the whole JSON schema to the client, which is something I'd like to avoid. The advantage JSON schema is that we also use it for generating Go code. We should find a way to use JSON schema but generate specific validators at build time.
There are also other libraries that do runtime validation and are smaller but they don't necessarily allow asynchronous validation (which we want to do because we only want to import the re2js library when necessary; of course we could organize the code differently but it's nice to be able to encapsulate this logic)

Test plan

Manual testing and new integration tests.

@fkling fkling requested review from camdencheek and vovakulikov July 5, 2024 21:57
@cla-bot cla-bot Bot added the cla-signed label Jul 5, 2024
@fkling fkling force-pushed the fkling-srch-692-respect-cody-ignore-feature branch from 2c58f8b to 012fa86 Compare July 5, 2024 22:01

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread client/web-sveltekit/src/lib/cody/CodySidebar.svelte Outdated
fkling added 2 commits July 8, 2024 20:56
This commit adds support for cody ignore settings to the SvelteKit app.
When cody is disabled on the instance or for the user, the cody button
and sidebar are not shown anymore.

Likewise if the repository is excluded from cody, the buttons and
sidebar are not shown.

The implementation was inspired by `useCodyIngore.ts`, but simplified
for use in the SvelteKit app. It seems that the file exclusion logic is
not actually used for the sidebar and thus was omitted. It also seems
that for the sidebar itself we are only checking whether the current
repository is excluded or not, which lets us simplify the whole setup
and simply pass a boolean (store) from the data loader, indicating
whether cody is enabled or not.

Furthermore I introduced zod to validate that the value of
`codyContextFilters.raw`, which is typed as `JSONValue`, has the
expected shape. We've run into issues in the past where such values
have just been cast to the expected Typescript type. zod adds runtime
validation.
Note that we use JSON schema base validation (with ajv) in some places,
but that requires importing and sending the whole JSON schema to the
client, which is something I'd like to avoid. The advantage JSON schema
is that we also use it for generating Go code. We should find a way to
use JSON schema but generate specific validators at build time.
There are also other libraries that do runtime validation and are
smaller but they don't necessarily allow asynchronous validation (which
we want to do because we only want to import the `re2js` library when
necessary).
@fkling fkling force-pushed the fkling-srch-692-respect-cody-ignore-feature branch from 3756701 to 14d33ca Compare July 8, 2024 18:56

@vovakulikov vovakulikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool approach with zod validation.

Comment thread client/web-sveltekit/src/lib/cody/config.ts Outdated
return
}

CodyContextFilters.safeParseAsync(filters).then(result => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool, maybe we could use the same approach from setting cascade later in other PRs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly... as I mentioned we use ajv in some places, which makes sense considering that the JSON schema can be shared between the client and the backend. But I also think that importing (i.e. sending) the whole schema to the client is wasteful. I'd like to find a solution where we can generate validation code at build time.
Then again, something like 'typing' the strings as re2 expressions and validating them is probably not possible with JSON schema alone.

@fkling fkling enabled auto-merge (squash) July 9, 2024 07:21
@fkling fkling merged commit fb1106b into main Jul 9, 2024
@fkling fkling deleted the fkling-srch-692-respect-cody-ignore-feature branch July 9, 2024 07:40
fkling added a commit that referenced this pull request Jul 9, 2024
Based on #63677 

Closes srch-691
Closes srch-695

This adds the cody button to the repo "home page" so that cody can be
opened from there.
This commit also makes it so that the cody button is hidden when the
sidebar opens (like in the React app) and it adds a fixed height to the
various headers so that they align well with the sidebar header and
don't change size when the cody button is hidden when the sidebar is
open.

## Test plan

Manual testing.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants