Skip to content

Commit ed1813c

Browse files
committed
✨ impl as web extension
1 parent 10cd953 commit ed1813c

18 files changed

+1149
-141
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/dist
33
node_modules
44
.vscode-test/
5+
.vscode-test-web/
56
*.vsix
67

78
**/.DS_store

.vscode/launch.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"outFiles": [
3232
"${workspaceFolder}/dist/**/*.js"
3333
],
34-
"preLaunchTask": "npm: watch-test",
34+
"preLaunchTask": "npm: watch-tsc",
3535
}
3636
]
3737
}

.vscode/tasks.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
},
2121
{
2222
"type": "npm",
23-
"script": "watch-test",
23+
"script": "watch-tsc",
2424
"problemMatcher": "$tsc-watch",
2525
"isBackground": true,
2626
"presentation": {
2727
"reveal": "never"
2828
},
29-
"label": "npm: watch-test"
29+
"label": "npm: watch-tsc"
3030
},
3131
{
3232
"type": "npm",

.vscodeignore

+19-20
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
1-
# ignore vscode settings
21
.vscode/**
3-
# ignore test
42
.vscode-test/**
5-
# ignore i18n
6-
README.*.md
7-
#ignore dev files
8-
src/**
3+
.vscode-test-web/**
4+
src/
5+
doc/
6+
pics/
7+
LICENSE
8+
samples/
9+
10+
**/test/**
11+
912
**/*.map
1013
**/*.ts
14+
**/*.md
15+
!README.md
16+
!CHANGELOG.md
17+
!resources/hoverinfo.md
18+
1119
**/.gitignore
1220
**/azure-pipelines.yml
1321
**/tsconfig.json
1422
**/.eslintrc.json
1523
**/gulpfile.js
1624
**/webpack.config.js
17-
# doc pic license samples
18-
doc/
19-
*/**.md
20-
!resources/hoverinfo.md
21-
pics/
22-
LICENSE
23-
samples/
2425

25-
# only package some file of tools folder to control the package size
26-
web/index.html
27-
web/test.jsdos
28-
tools/**.log
29-
#dosbox
30-
tools/dosbox/dosbox-0.74.conf
31-
tools/dosbox/std*.txt
26+
.vscodeignore
27+
28+
yarn.lock
29+
30+

package.json

+16-7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"onLanguage:masm"
3939
],
4040
"main": "./dist/extension.js",
41+
"browser": "./dist/web/extension.js",
4142
"contributes": {
4243
"languages": [
4344
{
@@ -279,25 +280,30 @@
279280
"scripts": {
280281
"clean": "rimraf dist/ web/dist",
281282
"postinstall": "node dev/downloadBundle.js",
282-
"compile": "webpack --mode production",
283+
"watch-tsc": "tsc -watch -p ./",
283284
"watch": "webpack --mode development --watch",
284-
"watch-test": "tsc -watch -p ./src",
285+
"compile": "webpack --mode production",
286+
"pretest": "tsc -p ./",
287+
"test": "node ./dist/test/runTest.js",
288+
"pretest-web": "yarn run compile",
289+
"test-web": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=. --extensionTestsPath=dist/web/test/suite/index.js",
290+
"run-in-browser": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=. .",
285291
"lint": "eslint src --ext ts",
286292
"lint-fix": "eslint src --ext ts --fix",
287-
"pretest": "tsc -p ./src",
288-
"test": "node ./dist/test/runTest.js",
289293
"vscode:prepublish": "yarn clean && yarn compile",
290-
"deploy": "vsce publish --yarn --baseContentUrl https://github.com/dosasm/masm-tasm/blob/main/ --baseImagesUrl https://github.com/dosasm/masm-tasm/raw/main/ ",
294+
"deploy": "vsce publish --yarn",
291295
"package": "vsce package"
292296
},
293297
"devDependencies": {
294298
"@types/glob": "^7.1.3",
295299
"@types/js-yaml": "^4.0.0",
296300
"@types/mocha": "^9.0.0",
297-
"@types/node": "^16.6.1",
298301
"@types/vscode": "^1.49.0",
302+
"@types/webpack-env": "^1.16.2",
299303
"@typescript-eslint/eslint-plugin": "^4.29.1",
300304
"@typescript-eslint/parser": "^4.29.1",
305+
"@vscode/test-web": "^0.0.13",
306+
"assert": "^2.0.0",
301307
"del": "^6.0.0",
302308
"download": "^8.0.0",
303309
"emulators": "^0.67.0",
@@ -306,6 +312,9 @@
306312
"js-yaml": "^4.0.0",
307313
"jszip": "^3.7.1",
308314
"mocha": "^9.0.3",
315+
"node-fetch": "^3.0.0",
316+
"path-browserify": "^1.0.1",
317+
"process": "^0.11.10",
309318
"rimraf": "^3.0.2",
310319
"ts-loader": "^9.2.5",
311320
"typescript": "^4.3.5",
@@ -323,4 +332,4 @@
323332
"email": "[email protected]"
324333
},
325334
"license": "MIT"
326-
}
335+
}

src/ASM/statusBar.ts

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ for (const e of emu) {
2323
if (a === conf.Assembler.TASM || a === conf.Assembler['MASM-v6.11'])
2424
continue;
2525
}
26+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
27+
if ((process as any).browser && e !== conf.DosEmulatorType.jsdos) {
28+
continue;
29+
}
2630
iterms.push(e + '\t' + a);
2731
}
2832
}

src/language/downloadFile.ts

-58
This file was deleted.

src/language/hoverFromCppdoc.ts

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from 'vscode';
2-
import * as down from './downloadFile';
2+
import * as down from '../utils/downloadFile';
33
import { keywordType } from './Hover';
44

55
const fs = vscode.workspace.fs;
@@ -42,8 +42,8 @@ class RESOURCES {
4242
};
4343

4444
static links = [
45-
'https://raw.fastgit.org/MicrosoftDocs/{repo}/{branch}/',
46-
'https://raw.githubusercontent.com/MicrosoftDocs/{repo}/{branch}/'
45+
'https://raw.githubusercontent.com/MicrosoftDocs/{repo}/{branch}/',
46+
'https://cdn.jsdelivr.net/gh/MicrosoftDocs/{repo}@{branch}/docs/',
4747
];
4848

4949
static getlinks(id: string, lang: string): string[] {
@@ -161,14 +161,8 @@ export class Cppdoc {
161161

162162
private async getText(ref: string): Promise<string | undefined> {
163163
const links = RESOURCES.getlinks(ref, vscode.env.language);
164-
165-
const dst = vscode.Uri.joinPath(this.dstFolder, `${ref}.md`);
166-
const code = await down.downloadFromMultiSources(links, dst.fsPath);
167-
if (code) {
168-
const arr = await fs.readFile(dst);
169-
return arr.toString();
170-
}
171-
return undefined;
164+
const str = await down.downloadFromMultiSources(links);
165+
return str;
172166
}
173167

174168
public async findKeyword(word: string, types: keywordType[]): Promise<string | undefined> {

src/tsconfig.json

-23
This file was deleted.

src/utils/browser-fetch.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default fetch;

src/utils/downloadFile.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* API for downloading information from web
3+
*/
4+
import { logger } from "./logger";
5+
import fetch from 'node-fetch';
6+
7+
export async function downloadFromMultiSources(urls: string[]): Promise<string | undefined> {
8+
for (const url of urls) {
9+
try {
10+
const data = await fetch(url);
11+
const val = await data.text();
12+
if (val) {
13+
return val;
14+
}
15+
} catch (e) {
16+
logger.channel(JSON.stringify(e)).show();
17+
}
18+
}
19+
}

src/web/extension.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as vscode from 'vscode';
2+
import { localize, loadI18n } from '../utils/i18n';
3+
4+
import * as lan from '../language/main';
5+
import * as asm from './main';
6+
7+
export function activate(context: vscode.ExtensionContext): void {
8+
9+
loadI18n(context);
10+
11+
//provide programmaic language features like hover,references,outline(symbol)
12+
lan.activate(context);
13+
//provide run and debug features via DOS emulators
14+
asm.activate(context);
15+
16+
console.log(localize("activate.hello", 'Congratulations, your extension "masm-tasm" is now active!'));
17+
}
18+
19+
// this method is called when your extension is deactivated
20+
export function deactivate(): void {
21+
console.log('extension deactivated');
22+
}

0 commit comments

Comments
 (0)