Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(website): [playground] use languageService for linting code#6806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
armano2 merged 12 commits intov6fromchore/playground-refactor-code-to-use-tsvfs
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
12 commits
Select commitHold shift + click to select a range
a9028d5
chore(website): [playground] use tsvfs as for linting code
armano2Mar 31, 2023
1f872c2
Merge branch 'v6' into chore/playground-refactor-code-to-use-tsvfs
armano2Apr 2, 2023
a655909
fix: correct issue after merge
armano2Apr 2, 2023
fec541d
Merge branch 'v6' into chore/playground-refactor-code-to-use-tsvfs
armano2Apr 2, 2023
0adaa65
fix: refactor linter back to class
armano2Apr 3, 2023
684833a
fix: apply changes from code review
armano2Apr 3, 2023
6f897b5
fix: revert conversion from createLinter to class
armano2Apr 3, 2023
223b947
fix: revert conversion from createLinter to class part 2
armano2Apr 3, 2023
403d8a1
fix: correct linting issue
armano2Apr 3, 2023
f49243d
Merge branch 'v6' into chore/playground-refactor-code-to-use-tsvfs
armano2Apr 3, 2023
2b17752
Merge branch 'v6' into chore/playground-refactor-code-to-use-tsvfs
armano2Apr 4, 2023
f04f533
Merge branch 'v6' into chore/playground-refactor-code-to-use-tsvfs
armano2Apr 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
413 changes: 181 additions & 232 deletionspackages/website/src/components/editor/LoadedEditor.tsx
View file
Open in desktop

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletionspackages/website/src/components/editor/loadSandbox.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
import type MonacoEditor from 'monaco-editor';

import type * as SandboxFactory from '../../vendor/sandbox';
import type {LintUtils } from '../linter/WebLinter';
import type {WebLinterModule } from '../linter/types';

type Monaco = typeof MonacoEditor;
type Sandbox = typeof SandboxFactory;

export interface SandboxModel {
main: Monaco;
sandboxFactory: Sandbox;
lintUtils:LintUtils;
lintUtils:WebLinterModule;
}

function loadSandbox(tsVersion: string): Promise<SandboxModel> {
Expand All@@ -32,7 +32,7 @@ function loadSandbox(tsVersion: string): Promise<SandboxModel> {
});

// Grab a copy of monaco, TypeScript and the sandbox
window.require<[Monaco, Sandbox,LintUtils]>(
window.require<[Monaco, Sandbox,WebLinterModule]>(
['vs/editor/editor.main', 'sandbox/index', 'linter/index'],
(main, sandboxFactory, lintUtils) => {
resolve({ main, sandboxFactory, lintUtils });
Expand Down
26 changes: 17 additions & 9 deletionspackages/website/src/components/editor/useSandboxServices.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,14 +4,15 @@ import { useEffect, useState } from 'react';

import type { createTypeScriptSandbox } from '../../vendor/sandbox';
import { createCompilerOptions } from '../lib/createCompilerOptions';
import { WebLinter } from '../linter/WebLinter';
import { createFileSystem } from '../linter/bridge';
import { type CreateLinter, createLinter } from '../linter/createLinter';
import type { PlaygroundSystem } from '../linter/types';
import type { RuleDetails } from '../types';
import { editorEmbedId } from './EditorEmbed';
import { sandboxSingleton } from './loadSandbox';
import type { CommonEditorProps } from './types';

export interface SandboxServicesProps {
readonly jsx?: boolean;
readonly onLoaded: (
ruleDetails: RuleDetails[],
tsVersions: readonly string[],
Expand All@@ -23,7 +24,8 @@ export type SandboxInstance = ReturnType<typeof createTypeScriptSandbox>;

export interface SandboxServices {
sandboxInstance: SandboxInstance;
webLinter: WebLinter;
system: PlaygroundSystem;
webLinter: CreateLinter;
}

export const useSandboxServices = (
Expand DownExpand Up@@ -67,22 +69,27 @@ export const useSandboxServices = (
colorMode === 'dark' ? 'vs-dark' : 'vs-light',
);

const libEntries = new Map<string, string>();
const system = createFileSystem(props, sandboxInstance.tsvfs);

const worker = await sandboxInstance.getWorkerProcess();
if (worker.getLibFiles) {
const libs = await worker.getLibFiles();
for (const [key, value] of Object.entries(libs)) {
libEntries.set('/' + key, value);
system.writeFile('/' + key, value);
}
}

constsystem =sandboxInstance.tsvfs.createSystem(libEntries);
window.system =system;
window.esquery = lintUtils.esquery;

const webLinter = new WebLinter(system, compilerOptions, lintUtils);
const webLinter = createLinter(
system,
lintUtils,
sandboxInstance.tsvfs,
);

onLoaded(
Array.from(webLinter.rulesMap.values()),
Array.from(webLinter.rules.values()),
Array.from(
new Set([...sandboxInstance.supportedVersions, window.ts.version]),
)
Expand All@@ -91,8 +98,9 @@ export const useSandboxServices = (
);

setServices({
sandboxInstance,
system,
webLinter,
sandboxInstance,
});
})
.catch(setServices);
Expand Down
19 changes: 19 additions & 0 deletionspackages/website/src/components/lib/createEventsBinder.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function createEventsBinder<T extends (...args: any[]) => void>(): {
trigger: (...args: Parameters<T>) => void;
register: (cb: T) => () => void;
} {
const events = new Set<T>();

return {
trigger(...args: Parameters<T>): void {
events.forEach(cb => cb(...args));
},
register(cb: T): () => void {
events.add(cb);
return (): void => {
events.delete(cb);
};
},
};
}
6 changes: 3 additions & 3 deletionspackages/website/src/components/lib/jsonSchema.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema';
import type * as ts from 'typescript';

import type {WebLinter } from '../linter/WebLinter';
import type {CreateLinter } from '../linter/createLinter';

/**
* Get the JSON schema for the eslint config
* Currently we only support the rules and extends
*/
export function getEslintJsonSchema(linter:WebLinter): JSONSchema4 {
export function getEslintJsonSchema(linter:CreateLinter): JSONSchema4 {
const properties: Record<string, JSONSchema4> = {};

for (const [, item] of linter.rulesMap) {
for (const [, item] of linter.rules) {
properties[item.name] = {
description: `${item.description}\n ${item.url}`,
title: item.name.startsWith('@typescript') ? 'Rules' : 'Core rules',
Expand Down
38 changes: 0 additions & 38 deletionspackages/website/src/components/linter/CompilerHost.ts
View file
Open in desktop

This file was deleted.

172 changes: 0 additions & 172 deletionspackages/website/src/components/linter/WebLinter.ts
View file
Open in desktop

This file was deleted.

Loading

[8]ページ先頭

©2009-2025 Movatter.jp