|
| 1 | +const GITHUB_BASE = "https://github.com/microsoft/vscode-cmake-tools/blob/main"; |
| 2 | + |
| 3 | +export interface DocsEntry { |
| 4 | + keywords: string[]; |
| 5 | + file: string; |
| 6 | + githubUrl: string; |
| 7 | + summary: string; |
| 8 | + keyHeadings: string[]; |
| 9 | +} |
| 10 | + |
| 11 | +function doc( |
| 12 | + keywords: string[], |
| 13 | + file: string, |
| 14 | + summary: string, |
| 15 | + keyHeadings: string[] |
| 16 | +): DocsEntry { |
| 17 | + return { |
| 18 | + keywords, |
| 19 | + file, |
| 20 | + githubUrl: `${GITHUB_BASE}/${file}`, |
| 21 | + summary, |
| 22 | + keyHeadings |
| 23 | + }; |
| 24 | +} |
| 25 | + |
| 26 | +export const docsMap: DocsEntry[] = [ |
| 27 | + doc( |
| 28 | + ["kit", "kits", "compiler", "toolchain"], |
| 29 | + "docs/kits.md", |
| 30 | + "Documents how kits are found, defined, and configured — including user-local kits, project kits, and scan behavior.", |
| 31 | + ["How kits are found and defined", "Kit options", "Specify a compiler", "Specify a toolchain", "Visual Studio"] |
| 32 | + ), |
| 33 | + doc( |
| 34 | + ["variant", "variants", "build type", "debug release", "cmake-variants"], |
| 35 | + "docs/variants.md", |
| 36 | + "Documents the cmake-variants.yaml schema and how variants apply build configurations like Debug/Release and shared/static linkage.", |
| 37 | + ["Example YAML variants file", "Variant schema", "Variant settings", "Variant options", "How variants are applied"] |
| 38 | + ), |
| 39 | + doc( |
| 40 | + ["preset", "presets", "cmakepresets", "cmake presets"], |
| 41 | + "docs/cmake-presets.md", |
| 42 | + "Full reference for CMakePresets.json support including configure, build, test, package, and workflow presets.", |
| 43 | + [ |
| 44 | + "Configure and build with CMake Presets", |
| 45 | + "Supported CMake and CMakePresets.json versions", |
| 46 | + "Enable CMakePresets.json", |
| 47 | + "Configure and build", |
| 48 | + "Add new presets", |
| 49 | + "Edit presets" |
| 50 | + ] |
| 51 | + ), |
| 52 | + doc( |
| 53 | + ["settings", "config", "configuration", "cmake settings", "settings.json"], |
| 54 | + "docs/cmake-settings.md", |
| 55 | + "Reference for all cmake-tools settings in settings.json, including variable substitution and build problem matchers.", |
| 56 | + ["CMake settings", "Variable substitution", "Environment variables", "Command substitution", "Additional build problem matchers"] |
| 57 | + ), |
| 58 | + doc( |
| 59 | + ["configure", "cmake configure", "configuration process"], |
| 60 | + "docs/configure.md", |
| 61 | + "Explains the CMake configure step — how it is triggered, what happens internally, clean configure, and CMake Debugger.", |
| 62 | + ["The CMake Tools configure step", "The configure step outside of CMake Tools", "Clean configure", "Configure with CMake Debugger"] |
| 63 | + ), |
| 64 | + doc( |
| 65 | + ["build", "compile", "cmake build", "build target"], |
| 66 | + "docs/build.md", |
| 67 | + "Explains how to build the default target, a single target, build tasks, build flags, and clean build.", |
| 68 | + ["Build the default target", "Build a single target", "Create a build task", "How CMake Tools builds", "Clean build"] |
| 69 | + ), |
| 70 | + doc( |
| 71 | + ["debug", "debugging", "launch", "debug target", "launch.json"], |
| 72 | + "docs/debug-launch.md", |
| 73 | + "Documents launch targets, quick debugging (no launch.json), launch.json integration for gdb/lldb/msvc, and debugging tests.", |
| 74 | + ["Select a launch target", "Debugging without a launch.json", "Debug using a launch.json file", "Debugging tests", "Run without debugging"] |
| 75 | + ), |
| 76 | + doc( |
| 77 | + ["cmake debug", "cmake script debug", "cmake debugger", "cmakelist debug"], |
| 78 | + "docs/debug.md", |
| 79 | + "Documents debugging CMake scripts themselves (not the built binary) — stepping through CMakeLists.txt.", |
| 80 | + ["Debugging from CMake Tools UI entry points", "Debugging from launch.json", "Example launch.json"] |
| 81 | + ), |
| 82 | + doc( |
| 83 | + ["troubleshoot", "troubleshooting", "error", "problem", "common issues"], |
| 84 | + "docs/troubleshoot.md", |
| 85 | + "Common issues and resolutions, logging levels, log file locations, and how to get help.", |
| 86 | + ["Common Issues and Resolutions", "Increase the logging level", "Check the log file", "Get help"] |
| 87 | + ), |
| 88 | + doc( |
| 89 | + ["faq", "frequently asked", "questions", "help"], |
| 90 | + "docs/faq.md", |
| 91 | + "Frequently asked questions about CMake Tools — getting help, detecting VS Code, learning CMake, and common tasks.", |
| 92 | + ["How can I get help?", "How can I detect when CMake is run from VS Code?", "How do I learn about CMake?", "How do I perform common tasks"] |
| 93 | + ), |
| 94 | + doc( |
| 95 | + ["task", "tasks", "tasks.json", "cmake task"], |
| 96 | + "docs/tasks.md", |
| 97 | + "Documents the VS Code task integration for CMake operations — configure, build, test, install, and clean tasks.", |
| 98 | + ["Configure with CMake Tools tasks", "Build with CMake Tools tasks", "Test with CMake Tools tasks", "Install/Clean/Clean-rebuild with CMake Tools tasks"] |
| 99 | + ), |
| 100 | + doc( |
| 101 | + ["how to", "howto", "getting started", "quick start", "tutorial"], |
| 102 | + "docs/how-to.md", |
| 103 | + "Quick how-to guide for common operations — creating projects, configuring, building, debugging, and IntelliSense setup.", |
| 104 | + ["Create a new project", "Configure a project", "Build a project", "Debug a project", "Set up include paths for C++ IntelliSense"] |
| 105 | + ), |
| 106 | + doc( |
| 107 | + ["options", "cmake options", "visibility", "status bar config"], |
| 108 | + "docs/cmake-options-configuration.md", |
| 109 | + "Documents CMake options visibility configuration — controlling which commands and status bar items are shown.", |
| 110 | + ["Default Settings Json", "Configuring your CMake Status Bar and Project Status View"] |
| 111 | + ) |
| 112 | +]; |
| 113 | + |
| 114 | +/** Get all known topic keywords for listing in error messages */ |
| 115 | +export function knownTopics(): string[] { |
| 116 | + const topics = new Set<string>(); |
| 117 | + for (const entry of docsMap) { |
| 118 | + for (const kw of entry.keywords) { |
| 119 | + topics.add(kw); |
| 120 | + } |
| 121 | + } |
| 122 | + return [...topics].sort(); |
| 123 | +} |
| 124 | + |
| 125 | +/** |
| 126 | + * Find the best matching docs entry for a topic string. |
| 127 | + * Returns entries sorted by keyword match count (best first). |
| 128 | + */ |
| 129 | +export function findDocsEntries(topic: string): DocsEntry[] { |
| 130 | + const inputWords = topic |
| 131 | + .toLowerCase() |
| 132 | + .split(/[\s,./\\]+/) |
| 133 | + .filter((w) => w.length > 1); |
| 134 | + |
| 135 | + const inputPhrase = topic.toLowerCase().trim(); |
| 136 | + |
| 137 | + const scored = docsMap |
| 138 | + .map((entry) => { |
| 139 | + let score = 0; |
| 140 | + for (const keyword of entry.keywords) { |
| 141 | + if (inputPhrase.includes(keyword.toLowerCase())) { |
| 142 | + score += 2; |
| 143 | + } else { |
| 144 | + const keywordWords = keyword.toLowerCase().split(/\s+/); |
| 145 | + for (const kw of keywordWords) { |
| 146 | + if (inputWords.includes(kw)) { |
| 147 | + score += 1; |
| 148 | + } |
| 149 | + } |
| 150 | + } |
| 151 | + } |
| 152 | + return { entry, score }; |
| 153 | + }) |
| 154 | + .filter((e) => e.score > 0) |
| 155 | + .sort((a, b) => b.score - a.score) |
| 156 | + .map((e) => e.entry); |
| 157 | + |
| 158 | + return scored; |
| 159 | +} |
0 commit comments