-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
141 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as vscode from 'vscode' | ||
import { LanguageClient } from 'vscode-languageclient/node' | ||
import * as path from 'path' | ||
import * as fs from 'fs' | ||
import { Message, QueryResult, kQueryUrl, MessageType, SelectSkSLResponseMessage, pipe } from '@workspace/runner-data' | ||
|
||
export class Runner { | ||
public static kCommand = 'sksl.showRunner' | ||
|
||
public constructor( | ||
private context: vscode.ExtensionContext, | ||
private client: LanguageClient, | ||
) {} | ||
|
||
public run(uri: vscode.Uri | undefined) { | ||
const panel = vscode.window.createWebviewPanel('sksl.runner', 'SkSL Runner', vscode.ViewColumn.Beside, { | ||
enableScripts: true, | ||
}) | ||
|
||
const htmlPath = this.context.asAbsolutePath(path.join('build', 'runner-ui', 'index.html')) | ||
panel.webview.html = fs.readFileSync(htmlPath).toString() | ||
|
||
if (uri) { | ||
this.selectSkSL(panel, uri) | ||
} | ||
|
||
panel.webview.onDidReceiveMessage( | ||
async (message: Message) => { | ||
switch (message.type) { | ||
case MessageType.kSelectSkSL: { | ||
const uris = await vscode.window.showOpenDialog({ | ||
canSelectFiles: true, | ||
canSelectFolders: false, | ||
canSelectMany: false, | ||
filters: { | ||
SkSL: ['sksl'], | ||
}, | ||
}) | ||
if (uris && uris.length >= 1) { | ||
this.selectSkSL(panel, uris[0]) | ||
} | ||
break | ||
} | ||
} | ||
}, | ||
undefined, | ||
this.context.subscriptions, | ||
) | ||
} | ||
|
||
private async selectSkSL(panel: vscode.WebviewPanel, uri: vscode.Uri) { | ||
panel.webview.postMessage( | ||
pipe<SelectSkSLResponseMessage>({ | ||
type: MessageType.kSelectSkSL, | ||
path: uri.toString(), | ||
}), | ||
) | ||
|
||
const buffer = fs.readFileSync(uri.fsPath) | ||
const result: QueryResult = await this.client.sendRequest(kQueryUrl, { | ||
source: buffer.toString(), | ||
}) | ||
console.log(result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,3 @@ | ||
export const kQueryUrl = 'sksl/query' | ||
|
||
export interface QueryParams { | ||
source: string | ||
} | ||
|
||
export interface SkSLUniform { | ||
type: string | ||
name: string | ||
} | ||
|
||
export const dummySkSLUniform: SkSLUniform = { | ||
type: '', | ||
name: '', | ||
} | ||
|
||
export interface QueryResult { | ||
succeed: boolean | ||
kind: string | ||
uniforms: SkSLUniform[] | ||
} | ||
|
||
export const dummyQueryResult: QueryResult = { | ||
succeed: false, | ||
kind: '', | ||
uniforms: [dummySkSLUniform], | ||
} | ||
export * from './message' | ||
export * from './url' | ||
export * from './wasm' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export enum MessageType { | ||
kSelectSkSL, | ||
kGetUniforms, | ||
} | ||
|
||
export interface Message { | ||
type: MessageType | ||
} | ||
|
||
export interface SelectSkSLRequestMessage extends Message { | ||
type: MessageType.kSelectSkSL | ||
} | ||
|
||
export interface SelectSkSLResponseMessage extends Message { | ||
type: MessageType.kSelectSkSL | ||
path: string | ||
} | ||
|
||
export function pipe<T>(t: T): T { | ||
return t | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const kQueryUrl = 'sksl/query' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export interface QueryParams { | ||
source: string | ||
} | ||
|
||
export interface SkSLUniform { | ||
type: string | ||
name: string | ||
} | ||
|
||
export const dummySkSLUniform: SkSLUniform = { | ||
type: '', | ||
name: '', | ||
} | ||
|
||
export interface QueryResult { | ||
succeed: boolean | ||
kind: string | ||
uniforms: SkSLUniform[] | ||
} | ||
|
||
export const dummyQueryResult: QueryResult = { | ||
succeed: false, | ||
kind: '', | ||
uniforms: [dummySkSLUniform], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.