File tree Expand file tree Collapse file tree 8 files changed +36
-20
lines changed
editor/codemirror/language-server Expand file tree Collapse file tree 8 files changed +36
-20
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import "./App.css";
1010import { DialogProvider } from "./common/use-dialogs" ;
1111import VisualViewPortCSSVariables from "./common/VisualViewportCSSVariables" ;
1212import { deployment , useDeployment } from "./deployment" ;
13- import { MicrobitWebUSBConnection } from "@microbit/microbit-connection" ;
13+ import { createWebUSBConnection } from "@microbit/microbit-connection" ;
1414import { DeviceContextProvider } from "./device/device-hooks" ;
1515import { MockDeviceConnection } from "./device/mock" ;
1616import DocumentationProvider from "./documentation/documentation-hooks" ;
@@ -40,7 +40,7 @@ const isMockDeviceMode = () =>
4040const logging = deployment . logging ;
4141const device = isMockDeviceMode ( )
4242 ? new MockDeviceConnection ( )
43- : new MicrobitWebUSBConnection ( { logging } ) ;
43+ : createWebUSBConnection ( { logging } ) ;
4444
4545const host = createHost ( logging ) ;
4646const fs = new FileSystem ( logging , host , fetchMicroPython ) ;
Original file line number Diff line number Diff line change @@ -15,13 +15,13 @@ import { useFileSystem } from "../fs/fs-hooks";
1515import { useLogging } from "../logging/logging-hooks" ;
1616import {
1717 ConnectionStatus ,
18- DeviceConnection ,
18+ MicrobitWebUSBConnection ,
1919 SerialDataEvent ,
2020 ConnectionStatusEvent ,
2121} from "@microbit/microbit-connection" ;
2222import { SimulatorDeviceConnection } from "./simulator" ;
2323
24- const DeviceContext = React . createContext < undefined | DeviceConnection > (
24+ const DeviceContext = React . createContext < undefined | MicrobitWebUSBConnection > (
2525 undefined
2626) ;
2727
@@ -234,7 +234,7 @@ export const DeviceContextProvider = ({
234234 value : device ,
235235 children,
236236} : {
237- value : DeviceConnection ;
237+ value : MicrobitWebUSBConnection ;
238238 children : ReactNode ;
239239} ) => {
240240 const syncStatusState = useState < SyncStatus > ( SyncStatus . OUT_OF_SYNC ) ;
Original file line number Diff line number Diff line change 66import {
77 BoardVersion ,
88 ConnectionStatus ,
9- DeviceConnection ,
109 DeviceConnectionEventMap ,
1110 FlashDataSource ,
1211 FlashEvent ,
@@ -15,6 +14,8 @@ import {
1514 DeviceError ,
1615 DeviceErrorCode ,
1716 TypedEventTarget ,
17+ MicrobitWebUSBConnection ,
18+ SerialConnectionEventMap ,
1819} from "@microbit/microbit-connection" ;
1920
2021/**
@@ -25,8 +26,8 @@ import {
2526 * the connected state without a real device.
2627 */
2728export class MockDeviceConnection
28- extends TypedEventTarget < DeviceConnectionEventMap >
29- implements DeviceConnection
29+ extends TypedEventTarget < DeviceConnectionEventMap & SerialConnectionEventMap >
30+ implements MicrobitWebUSBConnection
3031{
3132 status : ConnectionStatus = ( navigator as any ) . usb
3233 ? ConnectionStatus . NO_AUTHORIZED_DEVICE
@@ -51,6 +52,12 @@ export class MockDeviceConnection
5152 async initialize ( ) : Promise < void > { }
5253
5354 dispose ( ) { }
55+ getDeviceId ( ) : number | undefined {
56+ return undefined ;
57+ }
58+ setRequestDeviceExclusionFilters ( ) : void { }
59+ getDevice ( ) { }
60+ async softwareReset ( ) : Promise < void > { }
5461
5562 async connect ( ) : Promise < ConnectionStatus > {
5663 const next = this . connectResults . shift ( ) ;
Original file line number Diff line number Diff line change @@ -7,9 +7,10 @@ import {
77 BoardVersion ,
88 ConnectionStatus ,
99 ConnectionStatusEvent ,
10- DeviceConnection ,
1110 DeviceConnectionEventMap ,
1211 FlashEvent ,
12+ MicrobitWebUSBConnection ,
13+ SerialConnectionEventMap ,
1314 SerialDataEvent ,
1415 SerialResetEvent ,
1516 TypedEventTarget ,
@@ -178,8 +179,8 @@ class SimulatorEventMap extends DeviceConnectionEventMap {
178179 * This communicates with the iframe that is used to embed the simulator.
179180 */
180181export class SimulatorDeviceConnection
181- extends TypedEventTarget < SimulatorEventMap >
182- implements DeviceConnection
182+ extends TypedEventTarget < SimulatorEventMap & SerialConnectionEventMap >
183+ implements MicrobitWebUSBConnection
183184{
184185 status : ConnectionStatus = ConnectionStatus . NO_AUTHORIZED_DEVICE ;
185186 state : SimulatorState | undefined ;
@@ -425,4 +426,12 @@ export class SimulatorDeviceConnection
425426 "*"
426427 ) ;
427428 }
429+
430+ getDeviceId ( ) : number | undefined {
431+ return undefined ;
432+ }
433+ setRequestDeviceExclusionFilters ( ) : void { }
434+ async flash ( ) : Promise < void > { }
435+ getDevice ( ) { }
436+ async softwareReset ( ) : Promise < void > { }
428437}
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import { Text } from "@codemirror/state";
77import * as LSP from "vscode-languageserver-protocol" ;
88import { Action , Diagnostic } from "../lint/lint" ;
99import { positionToOffset } from "./positions" ;
10- import { DeviceConnection } from "@microbit/microbit-connection" ;
10+ import { MicrobitWebUSBConnection } from "@microbit/microbit-connection" ;
1111
1212const reportMicrobitVersionApiUnsupported =
1313 "reportMicrobitVersionApiUnsupported" ;
@@ -22,7 +22,7 @@ const severityMapping = {
2222export const diagnosticsMapping = (
2323 document : Text ,
2424 lspDiagnostics : LSP . Diagnostic [ ] ,
25- device : DeviceConnection ,
25+ device : MicrobitWebUSBConnection ,
2626 warnOnV2OnlyFeatures : boolean ,
2727 warnOnV2OnlyFeaturesAction : ( ) => Action
2828) : Diagnostic [ ] =>
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import { autocompletion } from "./autocompletion";
1717import { BaseLanguageServerView , clientFacet , uriFacet } from "./common" ;
1818import { diagnosticsMapping } from "./diagnostics" ;
1919import { signatureHelp } from "./signatureHelp" ;
20- import { DeviceConnection } from "@microbit/microbit-connection" ;
20+ import { MicrobitWebUSBConnection } from "@microbit/microbit-connection" ;
2121
2222/**
2323 * The main extension. This synchronises the diagnostics between the client
@@ -60,7 +60,7 @@ class LanguageServerView extends BaseLanguageServerView implements PluginValue {
6060
6161 constructor (
6262 view : EditorView ,
63- private device : DeviceConnection ,
63+ private device : MicrobitWebUSBConnection ,
6464 private intl : IntlShape ,
6565 private warnOnV2OnlyFeatures : boolean ,
6666 private disableV2OnlyFeaturesWarning : ( ) => void
@@ -126,7 +126,7 @@ interface Actions {
126126 */
127127export function languageServer (
128128 client : LanguageServerClient ,
129- device : DeviceConnection ,
129+ device : MicrobitWebUSBConnection ,
130130 uri : string ,
131131 intl : IntlShape ,
132132 logging : Logging ,
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ import { ActionFeedback } from "../common/use-action-feedback";
1919import { Dialogs } from "../common/use-dialogs" ;
2020import {
2121 ConnectionStatus ,
22- DeviceConnection ,
22+ MicrobitWebUSBConnection ,
2323 AfterRequestDevice ,
2424 FlashDataError ,
2525 DeviceError ,
@@ -105,7 +105,7 @@ export enum ConnectionAction {
105105export class ProjectActions {
106106 constructor (
107107 private fs : FileSystem ,
108- private device : DeviceConnection ,
108+ private device : MicrobitWebUSBConnection ,
109109 private actionFeedback : ActionFeedback ,
110110 private dialogs : Dialogs ,
111111 private setSelection : ( selection : WorkbenchSelection ) => void ,
Original file line number Diff line number Diff line change 33 *
44 * SPDX-License-Identifier: MIT
55 */
6+ import { MicrobitWebUSBConnection } from "@microbit/microbit-connection" ;
67import { Terminal } from "xterm" ;
7- import { DeviceConnection } from "@microbit/microbit-connection" ;
88import { Logging } from "../logging/logging" ;
99
1010/**
@@ -13,7 +13,7 @@ import { Logging } from "../logging/logging";
1313export class SerialActions {
1414 constructor (
1515 private terminal : React . RefObject < Terminal | undefined > ,
16- private device : DeviceConnection ,
16+ private device : MicrobitWebUSBConnection ,
1717 private onSerialSizeChange : ( size : "compact" | "open" ) => void ,
1818 private logging : Logging
1919 ) { }
You can’t perform that action at this time.
0 commit comments