Skip to content

Commit

Permalink
Make Live editor auto-complete WebGPU types
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Aug 17, 2023
1 parent cd23dd4 commit 13079f0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
2 changes: 2 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const path = require('path');
const liveEditor = require('@gfxfundamentals/live-editor');
const fixLinks = require('./build/fix-links.js');
const liveEditorPath = path.dirname(require.resolve('@gfxfundamentals/live-editor'));
const webgpuTypesPath = path.join(__dirname, 'node_modules', '@webgpu', 'types');

module.exports = function(grunt) {

Expand Down Expand Up @@ -63,6 +64,7 @@ module.exports = function(grunt) {
{ expand: false, src: '*', dest: 'out/', filter: noMdsNoFolders, },
{ expand: true, cwd: `${liveEditor.monacoEditor}/`, src: 'min/**', dest: 'out/monaco-editor/', nonull: true, },
{ expand: true, cwd: `${liveEditorPath}/src/`, src: '**', dest: 'out/webgpu/resources/', nonull: true, },
{ expand: true, cwd: `${webgpuTypesPath}/`, src: 'dist/**', dest: 'out/types/webgpu/', nonull: true, },
{ expand: true, src: 'webgpu/**', dest: 'out/', filter: noMds, },
{ expand: true, src: '3rdparty/**', dest: 'out/', },
],
Expand Down
40 changes: 20 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"main": "index.js",
"devDependencies": {
"@gfxfundamentals/lesson-builder": "github:gfxfundamentals/lesson-builder#v2.2.0",
"@gfxfundamentals/live-editor": "github:gfxfundamentals/live-editor#v1.4.0",
"@gfxfundamentals/live-editor": "github:gfxfundamentals/live-editor#v1.5.1",
"@types/estree": "^1.0.0",
"@types/jsdom": "^21.1.1",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"@typescript-eslint/typescript-estree": "^5.56.0",
"@webgpu/types": "^0.1.30",
"@webgpu/types": "^0.1.34",
"eslint": "^8.36.0",
"eslint-plugin-google-camelcase": "0.0.2",
"eslint-plugin-html": "^7.1.0",
Expand Down
17 changes: 17 additions & 0 deletions webgpu/resources/editor-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ function removeDotDotSlash(url) {
return newUrl;
}

async function getText(url) {
const req = await fetch(url);
return await req.text();
}

async function initEditor() {
/* global monaco */
if (typeof monaco !== 'undefined') {
const basePath = '/types/webgpu/dist/index.d.ts';
const text = await getText(basePath);
monaco.languages.typescript.javascriptDefaults.addExtraLib(text, '');
}


}

/**
* Fix any local URLs into fully qualified urls.
*
Expand Down Expand Up @@ -200,6 +216,7 @@ window.lessonEditorSettings = {
lessonSettings,
prepHTML,
getWorkerPreamble,
initEditor,
tags: ['webgpu', 'webgpufundamentals.org'],
name: 'WebGPUFundamentals',
icon: '/webgpu/lessons/resources/webgpufundamentals-icon-256.png',
Expand Down

0 comments on commit 13079f0

Please sign in to comment.