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

not send a default standard to IntelliSense #1696

Merged
merged 8 commits into from
Mar 16, 2021
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
21 changes: 10 additions & 11 deletions src/cpptools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ 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";


export interface CompileFlagInformation {
extraDefinitions: string[];
standard: StandardVersion;
standard?: StandardVersion;
targetArch: Architecture;
}

Expand All @@ -41,7 +40,7 @@ interface TargetDefaults {
defines: string[];
}

function parseCppStandard(std: string, can_use_gnu: boolean): StandardVersion|null {
function parseCppStandard(std: string, can_use_gnu: boolean): StandardVersion | undefined {
const is_gnu = can_use_gnu && std.startsWith('gnu');
if (std.endsWith('++2a') || std.endsWith('++20') || std.endsWith('++latest')) {
return is_gnu ? 'gnu++20' : 'c++20';
Expand All @@ -56,11 +55,11 @@ function parseCppStandard(std: string, can_use_gnu: boolean): StandardVersion|nu
} else if (std.endsWith('++98')) {
return is_gnu ? 'gnu++98' : 'c++98';
} else {
return null;
return undefined;
}
}

function parseCStandard(std: string, can_use_gnu: boolean): StandardVersion|null {
function parseCStandard(std: string, can_use_gnu: boolean): StandardVersion | undefined {
// GNU options from: https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options
const is_gnu = can_use_gnu && std.startsWith('gnu');
if (/(c|gnu)(90|89|iso9899:(1990|199409))/.test(std)) {
Expand All @@ -77,7 +76,7 @@ function parseCStandard(std: string, can_use_gnu: boolean): StandardVersion|null
return 'c11';
}
} else {
return null;
return undefined;
}
}

Expand Down Expand Up @@ -117,7 +116,7 @@ export function parseCompileFlags(cptVersion: cpt.Version, args: string[], lang?
const can_use_gnu_std = (cptVersion >= cpt.Version.v4);
const iter = args[Symbol.iterator]();
const extraDefinitions: string[] = [];
let standard: StandardVersion = (lang === 'C') ? 'c11' : 'c++17';
let standard: StandardVersion | undefined;
let targetArch: Architecture = undefined;
while (1) {
const {done, value} = iter.next();
Expand Down Expand Up @@ -167,24 +166,24 @@ export function parseCompileFlags(cptVersion: cpt.Version, args: string[], lang?
const std = value.substring(5);
if (lang === 'CXX' || lang === 'OBJCXX' || lang === 'CUDA' ) {
const s = parseCppStandard(std, can_use_gnu_std);
if (s === null) {
if (!s) {
log.warning(localize('unknown.control.gflag.cpp', 'Unknown C++ standard control flag: {0}', value));
} else {
standard = s;
}
} else if (lang === 'C' || lang === 'OBJC' ) {
const s = parseCStandard(std, can_use_gnu_std);
if (s === null) {
if (!s) {
log.warning(localize('unknown.control.gflag.c', 'Unknown C standard control flag: {0}', value));
} else {
standard = s;
}
} else if (lang === undefined) {
let s = parseCppStandard(std, can_use_gnu_std);
if (s === null) {
if (!s) {
s = parseCStandard(std, can_use_gnu_std);
}
if (s === null) {
if (!s) {
log.warning(localize('unknown.control.gflag', 'Unknown standard control flag: {0}', value));
} else {
standard = s;
Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/cpptools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ suite('CppTools tests', () => {
expect(info.extraDefinitions).to.eql(['FOO=BAR']);
info = parseCompileFlags(cpptoolsVersion4, ['-DFOO=BAR', '/D', 'BAZ=QUX']);
expect(info.extraDefinitions).to.eql(['FOO=BAR', 'BAZ=QUX']);
expect(info.standard).to.eql('c++17');
expect(info.standard).to.eql(undefined);
// Parse language standard
info = parseCompileFlags(cpptoolsVersion4, ['-std=c++03']);
expect(info.standard).to.eql('c++03');
Expand Down