Repository: electron/fiddle
Pull request #667 (2021-04-22 10:09:48)

fix: intellisense not working
Closes https://github.com/electron/fiddle/issues/577.

Fixes intellisense not working as a function of setting `nodeIntegrationInWorker: true` in the `BrowserWindow` options.

Ideally i'd like to narrow down the true fix but this shifts calls to `decomment` to `findModule` where they're invoked directly instead of via Worker thread - I think for now it's more important to regain this functionality while we search for a nicer long-term solution.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/39039339/badge)](https://coveralls.io/builds/39039339)

Coverage increased (+0.07%) to 95.251% when pulling **3d86cc7ee3dac3aa59cc005b1daa76e3088a8c40 on temp-fix-intellisense** into **980284a80a509295a9f2e87b283c4b960715bc39 on master**.


Patch:
diff --git a/src/main/windows.ts b/src/main/windows.ts
index 843726fb..f0d1be70 100644
--- a/src/main/windows.ts
+++ b/src/main/windows.ts
@@ -25,7 +25,6 @@ export function getMainWindowOptions(): Electron.BrowserWindowConstructorOptions
     webPreferences: {
       webviewTag: false,
       nodeIntegration: true,
-      nodeIntegrationInWorker: true,
       contextIsolation: false,
       preload: path.join(__dirname, '..', 'preload', 'preload'),
     },
diff --git a/src/renderer/npm.ts b/src/renderer/npm.ts
index dd82695d..ca082697 100644
--- a/src/renderer/npm.ts
+++ b/src/renderer/npm.ts
@@ -1,5 +1,6 @@
 import { EditorValues } from '../interfaces';
 import { exec } from '../utils/exec';
+import decomment from 'decomment';
 
 // Making TypeScript happy and avoiding "esModuleInterop" issues
 const { builtinModules } = require('module');
@@ -111,7 +112,7 @@ export async function findModules(input: string) {
   let match: RegExpMatchArray | null;
 
   /* decomment code with the esprima parser */
-  const code = await decommentWithWorker(input);
+  const code = await decomment(input);
 
   /* grab all global require matches in the text */
   while ((match = requiregx.exec(code) || null)) {
@@ -166,16 +167,3 @@ export function packageRun(
 ): Promise<string> {
   return exec(dir, `${packageManager} run ${command}`);
 }
-
-function decommentWithWorker(input: string): Promise<string> {
-  return new Promise((resolve, reject) => {
-    const worker = new Worker('../utils/decomment.ts');
-    worker.onmessage = function (event: MessageEvent<string>) {
-      resolve(event.data);
-    };
-    worker.postMessage(input);
-    worker.onerror = function (e) {
-      reject(e);
-    };
-  });
-}
diff --git a/src/utils/decomment.ts b/src/utils/decomment.ts
deleted file mode 100644
index 4f683b3c..00000000
--- a/src/utils/decomment.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import decomment from 'decomment';
-
-onmessage = function (event: MessageEvent<string>) {
-  postMessage(decomment(event.data));
-};


Test patch:
diff --git a/tests/main/windows-spec.ts b/tests/main/windows-spec.ts
index 43ef6cae..5b12b059 100644
--- a/tests/main/windows-spec.ts
+++ b/tests/main/windows-spec.ts
@@ -38,7 +38,6 @@ describe('windows', () => {
       webPreferences: {
         webviewTag: false,
         nodeIntegration: true,
-        nodeIntegrationInWorker: true,
         contextIsolation: false,
         preload: '/fake/path',
       },
diff --git a/tests/renderer/npm-spec.ts b/tests/renderer/npm-spec.ts
index 1e019a0b..159c3aa0 100644
--- a/tests/renderer/npm-spec.ts
+++ b/tests/renderer/npm-spec.ts
@@ -10,13 +10,10 @@ import {
 } from '../../src/renderer/npm';
 import { exec } from '../../src/utils/exec';
 import { overridePlatform, resetPlatform } from '../utils';
-import MockDecommentWorker from '../mocks/worker';
 import { DefaultEditorId } from '../../src/interfaces';
 jest.mock('decomment');
 jest.mock('../../src/utils/exec');
 
-window.Worker = MockDecommentWorker;
-
 describe('npm', () => {
   const mockBuiltins = `
     function hello() {