Skip to content

Commit 31bda64

Browse files
committed
add settings for set links
1 parent b6a6231 commit 31bda64

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,18 @@
265265
"default": true,
266266
"description": "%config.hover%"
267267
},
268+
"masmtasm.cpp-docs.links": {
269+
"type": "array",
270+
"items": {
271+
"type": "string"
272+
},
273+
"markdownDescription": "%config.cpp-docs.links%",
274+
"default": [
275+
"https://cdn.jsdelivr.net/gh/MicrosoftDocs/cpp-docs@master/",
276+
"https://raw.githubusercontent.com/MicrosoftDocs/cpp-docs/master/",
277+
"https://gitee.com/dosasm/cpp-docs/raw/master/"
278+
]
279+
},
268280
"masmtasm.dosbox.run": {
269281
"type": "string",
270282
"default": "choose",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
"config.boxconfig.description": "configuration for DOSBox, use format like the default value, see [dosbox](https://www.dosbox.com/wiki/Dosbox.conf),Please don't set `autoexec` here",
2121
"config.boxXconfig.description": "configuration for DOSBox-X, use format like the default value, see [dosbox-x](https://dosbox-x.com/wiki/), Please don't set `autoexec `here",
2222
"config.hover": "Display Hover information or not, restart VSCode to apply",
23+
"config.cpp-docs.links": "Links for fetch hover data from [cppdocs](https://github.com/MicrosoftDocs/cpp-docs). \"{vid}\" will be replaced as `Visual Studio Code Language ID`,\"{mid}\" will be replaced as `MLCP language code`, see [vscode-loc](https://github.com/microsoft/vscode-loc)",
2324
"config.PLF": "Experimental programmatic language features like outline,jump to definition/reference. Restart needed"
2425
}

package.nls.zh-cn.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
"config.boxconfig.description": "dosbox的配置信息,将会写到插件专用的配置文件中, 参见 [dosbox官网的说明](https://www.dosbox.com/wiki/Dosbox.conf),请勿设置`autoexec`",
2121
"config.boxXconfig.description": "dosbox-x的配置信息,将会写到插件专用的配置文件中, 参见 [dosbox-x官网的说明](https://dosbox-x.com/wiki/),请勿设置`autoexec`",
2222
"config.hover": "是否显示悬浮提示(hover),可能需要重启vscode来应用变更",
23+
"config.cpp-docs.links": "用于获取[cppdocs](https://github.com/MicrosoftDocs/cpp-docs)信息的链接, \"{vid}\"将被替换为`Visual Studio Code Language ID`,\"{mid}\" 将被替换为`MLCP language code`, 参见 [vscode-loc](https://github.com/microsoft/vscode-loc)",
2324
"config.PLF": "使用提供大纲,跳到定义,查找引用等programmatic features"
2425
}

src/language/hoverFromCppdoc.ts

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import * as vscode from 'vscode';
22
import * as down from '../utils/downloadFile';
33
import { keywordType } from './Hover';
44

5-
const fs = vscode.workspace.fs;
6-
75
class RESOURCES {
86

97
static unincluded: { sectionof: string; list: { name: string; id: string }[] }[] = [
@@ -21,7 +19,7 @@ class RESOURCES {
2119
];
2220

2321
/**mainly use information from https://github.com/microsoft/vscode-loc */
24-
static langMap: { [id: string]: string } = {
22+
static langMap: { [vscode_lang_id: string]: string } = {
2523
"zh-cn": "zh-cn",
2624
ja: "ja-jp",
2725
ru: "ru-ru",
@@ -41,35 +39,28 @@ class RESOURCES {
4139
//pl-pl has resources but vscode does not support this language
4240
};
4341

44-
static links = [
45-
'https://raw.githubusercontent.com/MicrosoftDocs/{repo}/{branch}/',
46-
'https://gitee.com/dosasm/{repo}/raw/{branch}/',
47-
'https://cdn.jsdelivr.net/gh/MicrosoftDocs/{repo}@{branch}/',
48-
];
49-
5042
/**get links from the cpp-docs id
5143
* The Microsoft has removed its localized docs repo from github
5244
* TODO: find a way to get the content of localized docs
5345
* see: https://github.com/MicrosoftDocs/cpp-docs
54-
* @param id
55-
* @param lang
46+
* @param id docs's id in 'docs/assembler/masm/' forder
47+
* @param lang vscode language Id https://github.com/microsoft/vscode-loc
5648
* @returns links for download
5749
*/
5850
static getlinks(id: string, lang: string, prefix = 'docs/assembler/masm/'): string[] {
59-
const links = [...RESOURCES.links];
60-
61-
// if (lang === 'zh-cn') {
62-
// links = ['https://gitee.com/dosasm/cpp-docs.zh-cn/raw/live/'];
63-
// }
64-
65-
const repoName = 'cpp-docs';
66-
const branchName = 'master';
67-
const downloadables = links.map(
68-
val => val.replace('{repo}', repoName)
69-
.replace('{branch}', branchName) + prefix + id + '.md'
70-
);
71-
72-
return downloadables;
51+
const links: string[] | undefined = vscode.workspace.getConfiguration("masmtasm").get("cpp-docs.links");
52+
53+
if (links) {
54+
const downloadables = links.map(
55+
val => {
56+
const link = val.replace('{vid}', lang)
57+
.replace('{mid}', this.langMap[lang]);
58+
return link + prefix + id + '.md';
59+
}
60+
);
61+
return downloadables;
62+
}
63+
return [];
7364
}
7465

7566
static generateFromCppdoc(text: string): CppdocInfoCollection {
@@ -122,10 +113,6 @@ export class Cppdoc {
122113
private collections: CppdocInfoCollection[] = [[], [], []];
123114
private missing: number[] = [];
124115

125-
private get dstFolder(): vscode.Uri {
126-
return vscode.Uri.joinPath(this.ctx.globalStorageUri, 'cpp-docs_' + vscode.env.language);
127-
}
128-
129116
constructor(private ctx: vscode.ExtensionContext) {
130117
Cppdoc.references.forEach(
131118
(ref, idx) => {
@@ -152,7 +139,6 @@ export class Cppdoc {
152139

153140
async addMissing(): Promise<void> {
154141
const stillmiss: number[] = [];
155-
await fs.createDirectory(this.dstFolder);
156142
for (const idx of this.missing) {
157143
const ref = Cppdoc.references[idx];
158144
const text = await this.getText(ref);

0 commit comments

Comments
 (0)