Skip to content

Add Re-Index Project Command #964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2024

Conversation

plemarquand
Copy link
Contributor

@plemarquand plemarquand commented Jul 10, 2024

Adds a command to trigger a re-indexing of the open project. Should only be needed when background indexing is enabled and it gets out of sync. While that is a bug, this can act as a temporary workaround.

Blocked By: swiftlang/sourcekit-lsp#1561, swiftlang/sourcekit-lsp#1563
Issue: #939

Adds a command to trigger a re-indexing of the open project. Should only
be needed when background indexing is enabled and it gets out of sync.
While that is a bug, this can act as a temporary workaround.

Blocked By: swiftlang/sourcekit-lsp#1561
Issue: swiftlang#939
const error = err as { code: number; message: string };
// methodNotFound, version of sourcekit-lsp is likely too old.
if (error.code === -32601) {
vscode.window.showWarningMessage(
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to check this in advance so that we can only show the command in the command palette if background indexing is enabled?

Copy link
Contributor

Choose a reason for hiding this comment

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

SourceKit-LSP should report this capability

src/commands.ts Outdated
@@ -817,6 +837,9 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
vscode.commands.registerCommand("swift.debugSnippet", () => debugSnippet(ctx)),
vscode.commands.registerCommand("swift.runPluginTask", () => runPluginTask()),
vscode.commands.registerCommand("swift.restartLSPServer", () => restartLSPServer(ctx)),
...(ctx.swiftVersion.isGreaterThanOrEqual(new Version(6, 0, 0))
? [vscode.commands.registerCommand("swift.reindexProject", () => reindexProject(ctx))]
Copy link
Member

Choose a reason for hiding this comment

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

You can actually add a "when" clause to the package.json to hide the command under certain circumstances. Otherwise, the command will still show up in the command palette and give an ugly error message if the user tries to run it. Take a look at contextKeys.ts to see how to add a new context key. There are a bunch of examples for the "when" clause in the package.json already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally we'd solve both these comments with a context key called supportsReindexing. It would be set by languageClient.initializeResult.capatiblities.experimental['workspace/triggerReindex'] which would be returned when you initialize the language server. However this capability doesn't exist.

@ahoppen Is this possible to add? If you agree I can work up a PR.

@plemarquand
Copy link
Contributor Author

I've updated the PR to check if the workspace/triggerReindex capability is reported by sourcekit-lsp. There is a corresponding PR here: swiftlang/sourcekit-lsp#1563

Copy link
Contributor

@adam-fowler adam-fowler left a comment

Choose a reason for hiding this comment

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

👍

@plemarquand plemarquand merged commit efb2f9f into swiftlang:main Jul 15, 2024
8 checks passed
@plemarquand plemarquand deleted the sourcekit-reindex-command branch July 15, 2024 14:31
@ahoppen
Copy link
Member

ahoppen commented Jul 16, 2024

Do you think it would also be possible to address this from #939?

If the request succeeds, a popup should be displayed saying something like: Re-indexing a project should never be necessary and indicates a bug in SourceKit-LSP. Please file an issue at https://github.com/swiftlang/sourcekit-lsp/issues/new describing which symbol was out-of-date and how you got into the state. If the user chooses to file an issue, we should enter the workflow to create a diagnose bundle.

plemarquand added a commit to plemarquand/vscode-swift that referenced this pull request Jul 16, 2024
Show a warning informing the user that they shouldn't have to reindex
the project, and doing so indicates a bug in SourceKit-LSP. Show a
button that links out to the SourceKit-LSP issue creation page,
prepopulating the issue title as "Symbol Indexing Issue".

Requested by @ahoppen in swiftlang#964 (comment)
plemarquand added a commit to plemarquand/vscode-swift that referenced this pull request Jul 16, 2024
Show a warning informing the user that they shouldn't have to reindex
the project, and doing so indicates a bug in SourceKit-LSP. Show a
button that links out to the SourceKit-LSP issue creation page,
prepopulating the issue title as "Symbol Indexing Issue".

Requested by @ahoppen in swiftlang#964 (comment)
plemarquand added a commit that referenced this pull request Jul 17, 2024
Show a warning informing the user that they shouldn't have to reindex
the project, and doing so indicates a bug in SourceKit-LSP. Show a
button that links out to the SourceKit-LSP issue creation page,
prepopulating the issue title as "Symbol Indexing Issue".

Requested by @ahoppen in #964 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants