Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

src/goLanguageServer.ts: remove fallbacks for features that cannot be opted-out of #3156

Merged
merged 2 commits into from
Apr 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 0 additions & 87 deletions src/goLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,10 @@ import {
HandleDiagnosticsSignature,
LanguageClient,
ProvideCompletionItemsSignature,
ProvideDefinitionSignature,
ProvideDocumentFormattingEditsSignature,
ProvideDocumentHighlightsSignature,
ProvideDocumentLinksSignature,
ProvideDocumentSymbolsSignature,
ProvideHoverSignature,
ProvideReferencesSignature,
ProvideRenameEditsSignature,
ProvideSignatureHelpSignature,
ProvideWorkspaceSymbolsSignature,
RevealOutputChannelOn
} from 'vscode-languageclient';
import { ProvideImplementationSignature } from 'vscode-languageclient/lib/implementation';
import { ProvideTypeDefinitionSignature } from 'vscode-languageclient/lib/typeDefinition';
import WebRequest = require('web-request');
import { GoDefinitionProvider } from './goDeclaration';
import { GoHoverProvider } from './goExtraInfo';
Expand All @@ -55,7 +45,6 @@ interface LanguageServerConfig {
flags: string[];
features: {
diagnostics: boolean;
format: boolean;
documentLink: boolean;
};
checkForUpdates: boolean;
Expand Down Expand Up @@ -114,17 +103,6 @@ export async function registerLanguageFeatures(ctx: vscode.ExtensionContext) {
},
revealOutputChannelOn: RevealOutputChannelOn.Never,
middleware: {
provideDocumentFormattingEdits: (
document: vscode.TextDocument,
options: FormattingOptions,
token: vscode.CancellationToken,
next: ProvideDocumentFormattingEditsSignature
) => {
if (!config.features.format) {
return [];
}
return next(document, options, token);
},
handleDiagnostics: (
uri: vscode.Uri,
diagnostics: vscode.Diagnostic[],
Expand Down Expand Up @@ -208,63 +186,6 @@ export async function registerLanguageFeatures(ctx: vscode.ExtensionContext) {
'The language server is not able to serve any features at the moment.'
);
}

// Fallback to default providers for unsupported or disabled features.

if (!capabilities.completionProvider) {
const provider = new GoCompletionItemProvider(ctx.globalState);
ctx.subscriptions.push(provider);
ctx.subscriptions.push(vscode.languages.registerCompletionItemProvider(GO_MODE, provider, '.', '"'));
}
if (!config.features.format || !capabilities.documentFormattingProvider) {
ctx.subscriptions.push(
vscode.languages.registerDocumentFormattingEditProvider(GO_MODE, new GoDocumentFormattingEditProvider())
);
}

if (!capabilities.renameProvider) {
ctx.subscriptions.push(vscode.languages.registerRenameProvider(GO_MODE, new GoRenameProvider()));
}

if (!capabilities.typeDefinitionProvider) {
ctx.subscriptions.push(
vscode.languages.registerTypeDefinitionProvider(GO_MODE, new GoTypeDefinitionProvider())
);
}

if (!capabilities.hoverProvider) {
ctx.subscriptions.push(vscode.languages.registerHoverProvider(GO_MODE, new GoHoverProvider()));
}

if (!capabilities.definitionProvider) {
ctx.subscriptions.push(vscode.languages.registerDefinitionProvider(GO_MODE, new GoDefinitionProvider()));
}

if (!capabilities.referencesProvider) {
ctx.subscriptions.push(vscode.languages.registerReferenceProvider(GO_MODE, new GoReferenceProvider()));
}

if (!capabilities.documentSymbolProvider) {
ctx.subscriptions.push(
vscode.languages.registerDocumentSymbolProvider(GO_MODE, new GoDocumentSymbolProvider())
);
}

if (!capabilities.signatureHelpProvider) {
ctx.subscriptions.push(
vscode.languages.registerSignatureHelpProvider(GO_MODE, new GoSignatureHelpProvider(), '(', ',')
);
}

if (!capabilities.workspaceSymbolProvider) {
ctx.subscriptions.push(vscode.languages.registerWorkspaceSymbolProvider(new GoWorkspaceSymbolProvider()));
}

if (!capabilities.implementationProvider) {
ctx.subscriptions.push(
vscode.languages.registerImplementationProvider(GO_MODE, new GoImplementationProvider())
);
}
});

let languageServerDisposable = c.start();
Expand All @@ -281,12 +202,6 @@ export async function registerLanguageFeatures(ctx: vscode.ExtensionContext) {
ctx.subscriptions.push(languageServerDisposable);
})
);

// gopls is the only language server that provides live diagnostics on type,
// so use gotype if it's not enabled.
if (!(toolName === 'gopls' && config.features['diagnostics'])) {
vscode.workspace.onDidChangeTextDocument(parseLiveFile, null, ctx.subscriptions);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wont we need this if user has opted out of diagnostics?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would prefer to avoid these types of fallbacks, as it can make debugging gopls issues difficult. I don't see a reason that someone would opt-out of gopls diagnostics on-type, but still want diagnostics on type from a different tool.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a reason that someone would opt-out of gopls diagnostics on-type, but still want diagnostics on type from a different tool.

Previously, it has been mainly due to the issues with the diagnostics feature from gopls. If we are saying that all of those issues are resolved, then my next question would be as to what are the cases where one doesnt want diagnostics on type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there is some set of people that prefer to have their diagnostics only show up on save, not on-type. I think at this point, if someone is having issues with gopls diagnostics, we should work with them to resolve the issue, or they can disable gopls, but we can't let people replace the diagnostics - it's too confusing for debugging purposes.

}
}

function watchLanguageServerConfiguration(e: vscode.ConfigurationChangeEvent) {
Expand Down Expand Up @@ -334,9 +249,7 @@ export function parseLanguageServerConfig(): LanguageServerConfig {
// TODO: We should have configs that match these names.
// Ultimately, we should have a centralized language server config rather than separate fields.
diagnostics: goConfig['languageServerExperimentalFeatures']['diagnostics'],
format: goConfig['languageServerExperimentalFeatures']['format'],
documentLink: goConfig['languageServerExperimentalFeatures']['documentLink'],
highlight: goConfig['languageServerExperimentalFeatures']['highlight']
},
checkForUpdates: goConfig['useGoProxyToCheckForToolUpdates']
};
Expand Down