Skip to content
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

Add command to log language service diagnostics #3489

Merged
merged 8 commits into from
Apr 19, 2019
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,11 @@
"command": "C_Cpp.BuildAndDebugActiveFile",
"title": "%c_cpp.command.buildAndDebugActiveFile.title%",
"category": "C/C++"
},
{
"command": "C_Cpp.LogDiagnostics",
"title": "%c_cpp.command.logDiagnostics.title%",
"category": "C/C++"
}
],
"keybindings": [
Expand Down
3 changes: 2 additions & 1 deletion Extension/package.nls.it.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"c_cpp.command.resumeParsing.title": "Riprendi l'analisi del codice",
"c_cpp.command.showParsingCommands.title": "Mostra comandi per l'analisi del codice",
"c_cpp.command.takeSurvey.title": "Partecipa al Sondaggio",
"c_cpp.command.buildAndDebugActiveFile.title": "Compila ed Esegui il debug del file attivo"
"c_cpp.command.buildAndDebugActiveFile.title": "Compila ed Esegui il debug del file attivo",
"c_cpp.command.logDiagnostics.title": "Registra Diagnostica"
}
3 changes: 2 additions & 1 deletion Extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"c_cpp.command.resumeParsing.title": "Resume parsing",
"c_cpp.command.showParsingCommands.title": "Show parsing commands",
"c_cpp.command.takeSurvey.title": "Take survey",
"c_cpp.command.buildAndDebugActiveFile.title": "Build and Debug Active File"
"c_cpp.command.buildAndDebugActiveFile.title": "Build and Debug Active File",
"c_cpp.command.logDiagnostics.title": "Log Diagnostics"
}
3 changes: 2 additions & 1 deletion Extension/package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"c_cpp.command.resumeParsing.title": "继续解析",
"c_cpp.command.showParsingCommands.title": "查看解析命令",
"c_cpp.command.takeSurvey.title": "调查问卷",
"c_cpp.command.buildAndDebugActiveFile.title": "生成和调试当前文件"
"c_cpp.command.buildAndDebugActiveFile.title": "生成和调试当前文件",
"c_cpp.command.logDiagnostics.title": "记录诊断"
}
19 changes: 19 additions & 0 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,17 @@ interface QueryTranslationUnitSourceResult {
configDisposition: QueryTranslationUnitSourceConfigDisposition;
}

interface GetDiagnosticsResult {
diagnostics: string;
}

// Requests
const NavigationListRequest: RequestType<TextDocumentIdentifier, string, void, void> = new RequestType<TextDocumentIdentifier, string, void, void>('cpptools/requestNavigationList');
const GoToDeclarationRequest: RequestType<void, void, void, void> = new RequestType<void, void, void, void>('cpptools/goToDeclaration');
const QueryCompilerDefaultsRequest: RequestType<QueryCompilerDefaultsParams, configs.CompilerDefaults, void, void> = new RequestType<QueryCompilerDefaultsParams, configs.CompilerDefaults, void, void>('cpptools/queryCompilerDefaults');
const QueryTranslationUnitSourceRequest: RequestType<QueryTranslationUnitSourceParams, QueryTranslationUnitSourceResult, void, void> = new RequestType<QueryTranslationUnitSourceParams, QueryTranslationUnitSourceResult, void, void>('cpptools/queryTranslationUnitSource');
const SwitchHeaderSourceRequest: RequestType<SwitchHeaderSourceParams, string, void, void> = new RequestType<SwitchHeaderSourceParams, string, void, void>('cpptools/didSwitchHeaderSource');
const GetDiagnosticsRequest: RequestType<void, GetDiagnosticsResult, void, void> = new RequestType<void, GetDiagnosticsResult, void, void>('cpptools/getDiagnostics');

// Notifications to the server
const DidOpenNotification: NotificationType<DidOpenTextDocumentParams, void> = new NotificationType<DidOpenTextDocumentParams, void>('textDocument/didOpen');
Expand Down Expand Up @@ -231,6 +236,7 @@ export interface Client {
updateCustomConfigurations(requestingProvider?: CustomConfigurationProvider1): Thenable<void>;
updateCustomBrowseConfiguration(requestingProvider?: CustomConfigurationProvider1): Thenable<void>;
provideCustomConfiguration(document: vscode.TextDocument): Promise<void>;
logDiagnostics(): Promise<void>;
getCurrentConfigName(): Thenable<string>;
getCompilerPath(): Thenable<string>;
getKnownCompilers(): Thenable<configs.KnownCompiler[]>;
Expand Down Expand Up @@ -276,6 +282,7 @@ class DefaultClient implements Client {
private trackedDocuments = new Set<vscode.TextDocument>();
private outputChannel: vscode.OutputChannel;
private debugChannel: vscode.OutputChannel;
private diagnosticsChannel: vscode.OutputChannel;
private crashTimes: number[] = [];
private isSupported: boolean = true;
private inactiveRegionsDecorations = new Map<string, DecorationRangesPair>();
Expand Down Expand Up @@ -638,6 +645,17 @@ class DefaultClient implements Client {
});
}

public async logDiagnostics(): Promise<void> {
let response: GetDiagnosticsResult = await this.requestWhenReady(() => this.languageClient.sendRequest(GetDiagnosticsRequest, null));
if (!this.diagnosticsChannel) {
this.diagnosticsChannel = vscode.window.createOutputChannel("C/C++ Diagnostics");
this.disposables.push(this.diagnosticsChannel);
}
let header: string = `-------- Diagnostics - ${new Date().toLocaleString()}\n`;
let version: string = `Version: ${util.packageJson.version}\n`;
this.diagnosticsChannel.appendLine(`${header}${version}${response.diagnostics}`);
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 an API to "show" or "focus" the output channel to ensure that the user can see the output when we log it?

}

public async provideCustomConfiguration(document: vscode.TextDocument): Promise<void> {
let tokenSource: CancellationTokenSource = new CancellationTokenSource();
let providers: CustomConfigurationProviderCollection = getCustomConfigProviders();
Expand Down Expand Up @@ -1446,6 +1464,7 @@ class NullClient implements Client {
updateCustomConfigurations(requestingProvider?: CustomConfigurationProvider1): Thenable<void> { return Promise.resolve(); }
updateCustomBrowseConfiguration(requestingProvider?: CustomConfigurationProvider1): Thenable<void> { return Promise.resolve(); }
provideCustomConfiguration(document: vscode.TextDocument): Promise<void> { return Promise.resolve(); }
logDiagnostics(): Promise<void> { return Promise.resolve(); }
getCurrentConfigName(): Thenable<string> { return Promise.resolve(""); }
getCompilerPath(): Thenable<string> { return Promise.resolve(""); }
getKnownCompilers(): Thenable<configs.KnownCompiler[]> { return Promise.resolve([]); }
Expand Down
6 changes: 6 additions & 0 deletions Extension/src/LanguageServer/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ export function registerCommands(): void {
disposables.push(vscode.commands.registerCommand('C_Cpp.ResumeParsing', onResumeParsing));
disposables.push(vscode.commands.registerCommand('C_Cpp.ShowParsingCommands', onShowParsingCommands));
disposables.push(vscode.commands.registerCommand('C_Cpp.TakeSurvey', onTakeSurvey));
disposables.push(vscode.commands.registerCommand('C_Cpp.LogDiagnostics', onLogDiagnostics));
disposables.push(vscode.commands.registerCommand('cpptools.activeConfigName', onGetActiveConfigName));
getTemporaryCommandRegistrarInstance().executeDelayedCommands();
}
Expand Down Expand Up @@ -880,6 +881,11 @@ function onGetActiveConfigName(): Thenable<string> {
return clients.ActiveClient.getCurrentConfigName();
}

function onLogDiagnostics(): void {
onActivationEvent();
clients.ActiveClient.logDiagnostics();
}

function reportMacCrashes(): void {
if (process.platform === "darwin") {
prevCrashFile = "";
Expand Down
3 changes: 2 additions & 1 deletion Extension/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class TemporaryCommandRegistrar {
"C_Cpp.PauseParsing",
"C_Cpp.ResumeParsing",
"C_Cpp.ShowParsingCommands",
"C_Cpp.TakeSurvey"
"C_Cpp.TakeSurvey",
"C_Cpp.LogDiagnostics"
];

constructor() {
Expand Down
1 change: 1 addition & 0 deletions Extension/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ function rewriteManifest(): Promise<void> {
"onCommand:C_Cpp.ResumeParsing",
"onCommand:C_Cpp.ShowParsingCommands",
"onCommand:C_Cpp.TakeSurvey",
"onCommand:C_Cpp.LogDiagnostics",
"onDebug",
"workspaceContains:/.vscode/c_cpp_properties.json"
];
Expand Down