Skip to content

Commit

Permalink
Add "forceInclude" field to VSCode template
Browse files Browse the repository at this point in the history
VScode doesn't recognize header files included via "-include" flag in "compilerArgs" field.
Instead, absolute paths to these files should be specified in a special section "forceInclude".
  • Loading branch information
valeros committed Feb 14, 2020
1 parent a57ea79 commit fbfbf34
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions platformio/ide/tpls/vscode/.vscode/c_cpp_properties.json.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
{
% import platform
% from os.path import commonprefix, dirname, isdir
% from os.path import commonprefix, dirname, isabs, isdir, isfile, join
%
% systype = platform.system().lower()
%
Expand All @@ -17,6 +17,35 @@
% return " " in flag and systype == "windows"
% end
%
% def _find_abs_path(inc, inc_paths):
% for path in inc_paths:
% if isfile(join(path, inc)):
% return join(path, inc)
% end
% end
% return inc
% end
%
% def _find_forced_includes(flags, inc_paths):
% result = []
% i = 0
% length = len(flags)
% while(i < length):
% if flags[i].startswith("-include"):
% i = i + 1
% if i < length and not flags[i].startswith("-"):
% inc = flags[i]
% if not isabs(inc):
% inc = _find_abs_path(inc, inc_paths)
% end
% result.append(to_unix_path(inc))
% end
% end
% i = i + 1
% end
% return result
% end
%
% def _split_flags(flags):
% result = []
% i = 0
Expand Down Expand Up @@ -83,17 +112,30 @@
% STD_RE = re.compile(r"\-std=[a-z\+]+(\d+)")
% cc_stds = STD_RE.findall(cc_flags)
% cxx_stds = STD_RE.findall(cxx_flags)
% cc_m_flags = _split_flags(cc_flags)
% forced_includes = _find_forced_includes(cc_m_flags, cleaned_includes)
%
% if cc_stds:
"cStandard": "c{{ cc_stds[-1] }}",
% end
% if cxx_stds:
"cppStandard": "c++{{ cxx_stds[-1] }}",
% end
% if forced_includes:
"forcedInclude": [
% for include in forced_includes:
"{{ include }}",
% end
""
],
% end
"compilerPath": "{{ cc_path }}",
"compilerArgs": [
% for flag in [ '"%s"' % _escape(f) if _escape_required(f) else f for f in _split_flags(
% cc_flags) if f.startswith(("-m", "-i", "@"))]:
% for flag in [
% '"%s"' % _escape(f) if _escape_required(f) else f
% for f in cc_m_flags
% if f.startswith(("-m", "-i", "@")) and not f.startswith("-include")
% ]:
"{{ flag }}",
% end
""
Expand Down

0 comments on commit fbfbf34

Please sign in to comment.