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 Log Diagnostics command #2141

Merged
merged 4 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
59 changes: 7 additions & 52 deletions docs/issue_template.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,23 @@
<!-- Thanks for your contribution! To make things easier, please fill out the template below. -->

<!--
If you are submitting a bug report, please check the "Common Issues" page in the
documentation:

https://vector-of-bool.github.io/docs/vscode-cmake-tools/common_issues.html

Your issue may have an existing solution
-->

<!-- If you have a question/suggestion/issue that doesn't fit this template,
feel free to delete the template and write any free text. -->

<!-- Please delete any unused sections. -->

### Brief Issue Summary

<!-- Put a short free-form summary here. -->

### Expected:

<!-- For behavioral issues and feature requests/enhancements, use a list of
steps to describe the problem or suggested behavior. For example: -->

1. Push button
2. Thing happens

### Apparent Behavior:

<!-- For behavioral issues, describe what is _actually_ happening. -->
<!-- If this is a bug, please provide clear instructions as to how we can reproduce the issue on our end. -->

<!-- For requests/enhancements, delete this section. -->
### CMake Tools Diagnostics

<!-- Example: -->

1. Push button
2. Nothing happens

### CMake Tools Log

<!-- For apparent bugs, place the contents of the CMake/Build output panel here. -->
<!-- For bugs, please run the `CMake: Log Diagnostics` command and paste the output here. -->

```
<!-- Paste the log contents HERE -->
<!-- Paste the `CMake: Log Diagnostics` output HERE -->
```

### Developer Tools Log
### Debug Log

<!-- For apparent bugs, place the contents of the developer tools console here. -->
<!-- For bugs, we would also appreciate it if you used the `"cmake.loggingLevel": "debug"` setting and pasted the CMake/Build output from the OUTPUT window. -->

```
<!-- Paste the log contents HERE -->
<!-- Paste the debug log contents HERE -->
```

### Platform and Versions

<!-- For issues, fill out the following. Otherwise delete this section. -->

- **Operating System**: <!-- Windows, Ubuntu, Fedora, macOS, etc. -->
- **CMake Version**: <!-- 3.7.3-rc, 2.8.12, etc. -->
- **VSCode Version**: <!-- 1.16.0, 1.17.2, etc. -->
- **CMake Tools Extension Version**: <!-- 0.10.2, etc. -->
- **Compiler/Toolchain**: <!-- Visual C++ 2017, GCC 5.3, etc. -->

### Other Notes/Information

<!-- Write whatever you feel is relevant -->
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@
"when": "cmake:enableFullFeatureSet",
"category": "CMake"
},
{
"command": "cmake.logDiagnostics",
"title": "%cmake-tools.command.cmake.logDiagnostics.title%",
"when": "cmake:enableFullFeatureSet",
"category": "CMake"
},
{
"command": "cmake.selectActiveFolder",
"title": "%cmake-tools.command.cmake.selectActiveFolder.title%",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"cmake-tools.command.cmake.selectBuildPreset.title": "Select Build Preset",
"cmake-tools.command.cmake.selectTestPreset.title": "Select Test Preset",
"cmake-tools.command.cmake.viewLog.title": "Open the CMake Tools Log File",
"cmake-tools.command.cmake.logDiagnostics.title": "Log Diagnostics",
"cmake-tools.command.cmake.editKits.title": "Edit User-Local CMake Kits",
"cmake-tools.command.cmake.scanForKits.title": "Scan for Kits",
"cmake-tools.command.cmake.scanForCompilers.title": "Scan for Compilers",
Expand Down
74 changes: 67 additions & 7 deletions src/cpptools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as path from 'path';
import * as vscode from 'vscode';
import * as cpt from 'vscode-cpptools';
import * as nls from 'vscode-nls';
import { TargetTypeString } from './drivers/cms-client';

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
Expand All @@ -24,6 +25,22 @@ type Architecture = 'x86' | 'x64' | 'arm' | 'arm64' | undefined;
type StandardVersion = "c89" | "c99" | "c11" | "c17" | "c++98" | "c++03" | "c++11" | "c++14" | "c++17" | "c++20"
| "gnu89" | "gnu99" | "gnu11" | "gnu17" | "gnu++98" | "gnu++03" | "gnu++11" | "gnu++14" | "gnu++17" | "gnu++20" | undefined;

export interface DiagnosticsCpptools {
isReady: boolean;
hasCodeModel: boolean;
targetCount: number;
executablesCount: number;
librariesCount: number;
targets: DiagnosticsTarget[];
requests: string[];
responses: cpt.SourceFileConfigurationItem[];
}

export interface DiagnosticsTarget {
name: string;
type: TargetTypeString;
}

export interface CompileFlagInformation {
extraDefinitions: string[];
standard?: StandardVersion;
Expand Down Expand Up @@ -324,30 +341,48 @@ export class CppConfigurationProvider implements cpt.CustomConfigurationProvider
* Test if we are able to provide a configuration for the given URI
* @param uri The URI to look up
*/
async canProvideConfiguration(uri: vscode.Uri) { return !!this._getConfiguration(uri); }
async canProvideConfiguration(uri: vscode.Uri) {
this.requests.add(uri.toString());
return !!this._getConfiguration(uri);
}

private requests = new Set<string>();
private responses = new Map<string, cpt.SourceFileConfigurationItem>();

/**
* Get the configurations for the given URIs. URIs for which we have no
* configuration are simply ignored.
* @param uris The file URIs to look up
*/
async provideConfigurations(uris: vscode.Uri[]) { return util.dropNulls(uris.map(u => this._getConfiguration(u))); }
async provideConfigurations(uris: vscode.Uri[]) {
const configs = util.dropNulls(uris.map(u => this._getConfiguration(u)));
configs.forEach(config => {
this.responses.set(config.uri.toString(), config);
});
return configs;
}

/**
* A request to determine whether this provider can provide a code browsing configuration for the workspace folder.
* @param token (optional) The cancellation token.
* @returns 'true' if this provider can provider a code browsing configuration for the workspace folder.
*/
async canProvideBrowseConfiguration() { return true; }
async canProvideBrowseConfiguration() {
return true;
}

/**
* A request to get the code browsing configuration for the workspace folder.
* @returns A [WorkspaceBrowseConfiguration](#WorkspaceBrowseConfiguration) with the information required to
* construct the equivalent of `browse.path` from `c_cpp_properties.json`.
*/
async provideBrowseConfiguration() { return this._workspaceBrowseConfiguration; }
async provideBrowseConfiguration() {
return this._workspaceBrowseConfiguration;
}

async canProvideBrowseConfigurationsPerFolder() { return true; }
async canProvideBrowseConfigurationsPerFolder() {
return true;
}

async provideFolderBrowseConfiguration(_uri: vscode.Uri): Promise<cpt.WorkspaceBrowseConfiguration> {
return this._workspaceBrowseConfigurations.get(util.platformNormalizePath(_uri.fsPath)) ?? this._workspaceBrowseConfiguration;
Expand Down Expand Up @@ -397,8 +432,7 @@ export class CppConfigurationProvider implements cpt.CustomConfigurationProvider
}

const targetFromToolchains = comp_toolchains?.target;
const targetArchFromToolchains = targetFromToolchains
? parseTargetArch(targetFromToolchains) : undefined;
const targetArchFromToolchains = targetFromToolchains ? parseTargetArch(targetFromToolchains) : undefined;

const normalizedCompilerPath = util.platformNormalizePath(comp_path);
const flags = fileGroup.compileFlags ? [...shlex.split(fileGroup.compileFlags)] : target.compileFlags;
Expand Down Expand Up @@ -487,11 +521,18 @@ export class CppConfigurationProvider implements cpt.CustomConfigurationProvider
this._cpptoolsVersion = value;
}

private targets: DiagnosticsTarget[] = [];

/**
* Update the file index and code model
* @param opts Update parameters
*/
updateConfigurationData(opts: codemodel_api.CodeModelParams) {
// Reset the counters for diagnostics
this.requests.clear();
this.responses.clear();
this.targets = [];

let hadMissingCompilers = false;
this._workspaceBrowseConfiguration = {browsePath: []};
this._activeTarget = opts.activeTarget;
Expand All @@ -509,6 +550,7 @@ export class CppConfigurationProvider implements cpt.CustomConfigurationProvider
const compileFlags = [...util.flatMap(grps, grp => shlex.split(grp.compileFlags || ''))];
const defines = [...new Set(util.flatMap(grps, grp => grp.defines || []))];
const sysroot = target.sysroot || '';
this.targets.push({ name: target.name, type: target.type });
for (const grp of target.fileGroups || []) {
try {
this._updateFileGroup(
Expand Down Expand Up @@ -542,4 +584,22 @@ export class CppConfigurationProvider implements cpt.CustomConfigurationProvider
}
this._lastUpdateSucceeded = !hadMissingCompilers;
}

private ready: boolean = false;
markAsReady() {
this.ready = true;
}

getDiagnostics(): DiagnosticsCpptools {
return {
isReady: this.ready,
hasCodeModel: this._fileIndex.size > 0,
requests: [...this.requests.values() ],
responses: [...this.responses.values()],
targetCount: this.targets.length,
executablesCount: this.targets.reduce<number>((acc, target) => target.type === 'EXECUTABLE' ? acc + 1 : acc, 0),
librariesCount: this.targets.reduce<number>((acc, target) => target.type.endsWith('LIBRARY') ? acc + 1 : acc, 0),
targets: this.targets.length < 20 ? this.targets : []
};
}
}
18 changes: 16 additions & 2 deletions src/drivers/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import * as nls from 'vscode-nls';
import { majorVersionSemver, minorVersionSemver, parseTargetTriple, TargetTriple } from '@cmt/triple';
import * as preset from '@cmt/preset';
import * as codemodel from '@cmt/drivers/codemodel-driver-interface';
import {DiagnosticsConfiguration} from '@cmt/folders';

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
Expand Down Expand Up @@ -1219,14 +1220,14 @@ export abstract class CMakeDriver implements vscode.Disposable {
let telemetryProperties: telemetry.Properties;
if (this.useCMakePresets) {
telemetryProperties = {
CMakeExecutableVersion: cmakeVersion ? `${cmakeVersion.major}.${cmakeVersion.minor}.${cmakeVersion.patch}` : '',
CMakeExecutableVersion: cmakeVersion ? util.versionToString(cmakeVersion) : '',
CMakeGenerator: this.generatorName || '',
Preset: this.useCMakePresets ? 'true' : 'false',
Trigger: trigger
};
} else {
telemetryProperties = {
CMakeExecutableVersion: cmakeVersion ? `${cmakeVersion.major}.${cmakeVersion.minor}.${cmakeVersion.patch}` : '',
CMakeExecutableVersion: cmakeVersion ? util.versionToString(cmakeVersion) : '',
CMakeGenerator: this.generatorName || '',
ConfigType: this.isMultiConf ? 'MultiConf' : this.currentBuildType || '',
Toolchain: this._kit?.toolchainFile ? 'true' : 'false', // UseToolchain?
Expand Down Expand Up @@ -1672,4 +1673,17 @@ export abstract class CMakeDriver implements vscode.Disposable {
return inst;
}

public getDiagnostics(): DiagnosticsConfiguration {
return {
folder: this.workspaceFolder || '',
cmakeVersion: this.cmake.version ? util.versionToString(this.cmake.version) : '',
configured: this._isConfiguredAtLeastOnce,
generator: this.generatorName || '',
usesPresets: this.useCMakePresets,
compilers: {
C: this.cmakeCacheEntries.get('CMAKE_C_COMPILER')?.value,
CXX: this.cmakeCacheEntries.get('CMAKE_CXX_COMPILER')?.value
}
};
}
}
Loading