Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Feature] Add a small code snippet before every problem solutions#972

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Wang-Ji20 wants to merge3 commits intoLeetCode-OpenSource:master
base:master
Choose a base branch
Loading
fromWang-Ji20:master
Open
Show file tree
Hide file tree
Changes fromall 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 deletionspackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -323,6 +323,11 @@
"scope": "application",
"description": "Default language for solving the problems."
},
"leetcode.language.preamble": {
"type": "object",
"scope": "application",
"description": "A little preamble adding to each language's solution files"
},
"leetcode.showDescription": {
"type": "string",
"default": "In Webview",
Expand Down
4 changes: 3 additions & 1 deletionsrc/leetCodeExecutor.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ import { executeCommand, executeCommandWithProgress } from "./utils/cpUtils";
import { DialogOptions, openUrl } from "./utils/uiUtils";
import * as wsl from "./utils/wslUtils";
import { toWslPath, useWsl } from "./utils/wslUtils";
import { getCodePreamble } from "./utils/settingUtils";

class LeetCodeExecutor implements Disposable {
private leetCodeRootPath: string;
Expand DownExpand Up@@ -110,8 +111,9 @@ class LeetCodeExecutor implements Disposable {

if (!await fse.pathExists(filePath)) {
await fse.createFile(filePath);
const codePreamble: string = getCodePreamble(language);
const codeTemplate: string = await this.executeCommandWithProgressEx("Fetching problem data...", this.nodeExecutable, cmd);
await fse.writeFile(filePath, codeTemplate);
await fse.writeFile(filePath,codePreamble +codeTemplate);
}
}

Expand Down
124 changes: 124 additions & 0 deletionssrc/utils/settingUtils.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,6 +62,130 @@ export function getDescriptionConfiguration(): IDescriptionConfiguration {
return config;
}

const defaultPreambles = {
"cpp": `
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
`
}

/**
* ## About
*
* Code preamble is a short code snippet adding to the beginning of the program. A typical one is:
*
*
* ```
* #include <iostream>
* using namespace std;
* ```
*
* This feature is useful. Maybe inserting header files is interesting for the first several times,
* it is dreadful if we need to add tons of it each time we do the problems, especially for a dreadful
* language like C/C++
*
* ## Configuration
*
* To add a preamble for one language, the user will follow this schema:
*
* ```
* "leetcode.language.preamble" = {
* "cpp" : "#include <iostream>",
* }
* ```
*
* @param language
*/
export function getCodePreamble(language: string): string {
const preambles = getWorkspaceConfiguration().get<Record<string, string>>("language.preamble");
return preambles?.[language] ?? defaultPreambles?.[language] ?? "";
}

export interface IDescriptionConfiguration {
showInComment: boolean;
showInWebview: boolean;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp