Skip to content

Commit

Permalink
Make it work in VS Code for the Web (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
stkb committed Feb 7, 2022
1 parent 17bbc72 commit b1f9105
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
"sourceMaps": true,
"preLaunchTask": "Build extension"
},
{
"name": "Web Extension",
"type": "pwa-extensionHost",
"debugWebWorkerHost": true,
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/vscode",
"--extensionDevelopmentKind=web"
],
"sourceMaps": true,
"preLaunchTask": "Build extension"
},
{
"name": "Core Tests",
"type": "node",
Expand Down
11 changes: 10 additions & 1 deletion vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"onCommand:rewrap.toggleAutoWrap"
],
"main": "./dist/Extension.js",
"browser": "./dist/Extension.js",
"capabilities": {
"untrustedWorkspaces": {
"supported": true
Expand Down Expand Up @@ -124,5 +125,13 @@
"fast-diff": "^1.2.0",
"json5": "^2.2.0"
},
"source": "src/Extension.ts"
"source": "src/Extension.ts",
"targets": {
"main": {
"includeNodeModules": {
"vscode": false
}
},
"browser": false
}
}
15 changes: 8 additions & 7 deletions vscode/src/CustomLanguage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as Path from 'path'
import {readFileSync} from 'fs'
import * as JSON from 'json5'
import * as vscode from 'vscode'
import JSON from 'json5'
import vscode from 'vscode'
import {CustomMarkers, noCustomMarkers} from './Core'

const getConfig = (getText, path) => {
Expand Down Expand Up @@ -34,14 +32,14 @@ type Cache = Record<string, string | CustomMarkers>
/** Iterates through all extensions and populates the cache with mappings for each found
* language id to a path to a configuration file. */
function createCache (exts) : Cache {
const addConfigFiles = (cache, ext) => {
const addConfigFiles = (cache, ext: vscode.Extension<any>) => {
try {
let obj = ext.packageJSON
if ((obj = obj.contributes) && (obj = obj.languages)) {
for (const l of obj) {
if (!l.id) continue
if (l.configuration) {
const confPath = Path.join(ext.extensionPath, l.configuration)
const confPath = ext.extensionPath + '/' + l.configuration
cache[l.id] = confPath
}
}
Expand All @@ -61,8 +59,11 @@ export default function (exts?, getFileText?) {
exts = exts || vscode.extensions.all
if (!exts.length)
console.warn("`vscode.extensions.all` returned an empty array. Something is wrong.")
if (!getFileText) {
try { getFileText = require('fs').readFileSync }
catch { getFileText = () => "" }
}

getFileText = getFileText || (p => readFileSync(p))
let cache
return lang => {
cache = cache || createCache(exts)
Expand Down

0 comments on commit b1f9105

Please # to comment.