Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax color issue #836

Closed
NoMoreDeps opened this issue Sep 2, 2020 · 3 comments
Closed

Syntax color issue #836

NoMoreDeps opened this issue Sep 2, 2020 · 3 comments

Comments

@NoMoreDeps
Copy link

We have written the need
Issue Type: Bug

Following this sample of code :

image

The syntax color is correct, but if I format it differently, the last statement loses syntax coloration.

image

VS Code version: Code - Insiders 1.49.0-insider (b6d4fec3714ff897f72c1dab8cc02b7421a8f131, 2020-09-01T05:54:42.740Z)
OS version: Windows_NT x64 10.0.19041

System Info
Item Value
CPUs Intel(R) Xeon(R) CPU E5-1650 0 @ 3.20GHz (12 x 3192)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
opengl: enabled_on
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.95GB (8.51GB free)
Process Argv --crash-reporter-id bf356a28-e8c2-49fc-94e2-539aed5d2ce9
Screen Reader no
VM 0%
Extensions (5)
Extension Author (truncated) Version
shadow-align fsk 1.0.6
mongodb-vscode mon 0.1.1
vscode-docker ms- 1.5.0
remote-containers ms- 0.138.0
remote-wsl ms- 0.44.5
ed data into your clipboard because it was too large to send. Please paste.
@mjbvz
Copy link
Contributor

mjbvz commented Sep 3, 2020

Please share the text of the code along with screenshots

@NoMoreDeps
Copy link
Author

Hi, sorry for that :-)

The code on the screenshot :

 const _actions = {} as {
    [P in keyof Actions] : PropType<Parameters<Actions[P]> , "0"> extends object ? 
      (payload: PropType<Parameters<Actions[P]> , "0">) => void 
      : 
      () => void;
  };

And this is the full file :

import { Dispatcher }      from "../Core/Dispatcher"      ;
import { EventBusAutoOff } from "../Utils/Event/EventBus" ;

export type TBaseStore<T> = {
  id         ?: string                                                         ;
  nextState   : (newState: Partial<T>, mergeToPreviousState?: boolean) => void ;
  sendAction  : <U>(type: string, payload: U) => void                          ;
}

export class BaseStore<T> {
  protected state     !: T                                                                                                                                 ;
  id                   : string = ""                                                                                                                       ;
  mappedActions       ?: { [key: string] : string; }                                                                                                       ;
  protected init       : () => void = () => void 0                                                                                                         ;
  protected nextState  : (newState: Partial<T>, mergeToPreviousState?: boolean) => void = (newState: Partial<T>, mergeToPreviousState?: boolean) => void 0 ;
  protected sendAction : <T>(type: string, payload: T) => void = <T>(type: string, payload: T) => void 0                                                   ;
  getState() {
    return this.state;
  }
}

export type TExtentedStore<T> = TBaseStore<T> & {
  mappedActions ?: { [key: string] : string; }
}

export type TStoreDefinition<S, T, U> = {
  id              ?: string                                                               ;
  localActions    ?: boolean                                                              ;
  actions          : T                                                                    ;
  events          ?: U                                                                    ;
  mappedActions   ?: { [key: string] : string; }                                          ;
  init            ?: () => void                                                           ;
  dispatchHandler ?:(this: BaseStore<S>, payload: any, For? : TAwaitFor) => Promise<void> ;
  nextState       ?: (newState: Partial<S>, mergeToPreviousState?: boolean) => void       ;
}

type TRegisterSystem = {
  __dispatcher: Dispatcher;
}

export type TActionHandler<T> = (payload: T, For?: TAwaitFor) => TActionReturn ;
export type TActionReturn     = Promise<undefined | null | string | string[]>  ;
export type TAwaitFor         = (...ids: string[]) => Promise<void>            ;

export function withEvents<T>(source: T) {
  for(const i in source) {
    (source as any)[i] = i;
  }
  return source as T;
}

type PropType<TObj, TProp extends keyof TObj> = TObj[TProp];

type TActionExtention = {[key: string]: (...args: any) => Promise<void | null | string | string[]>};

function _registerStore<State, Actions extends TActionExtention, Events extends { [key: string]: string}> (this: any, def: TStoreDefinition<State, Actions, Events>) {
  const _this = <TRegisterSystem>this;
  
  if (!_this.__dispatcher) _this.__dispatcher = new Dispatcher();
  const store = new BaseStore<State>();
  store.mappedActions = def.mappedActions;
  _this.__dispatcher.registerStore(store, def.id);

  const _actions = {} as {
    [P in keyof Actions] : PropType<Parameters<Actions[P]> , "0"> extends object ? 
      (payload: PropType<Parameters<Actions[P]> , "0">) => void 
      : 
      () => void;
  };

  for (const key in def.actions) {
    (_actions as any)[key] = (_: any) => {
      _this.__dispatcher.dispatch({type: def.localActions ? `${def.id}-${key}` : key, ..._});
    };
    (store as any)[def.localActions ? `${def.id}-${key}` : key] = def.actions[key];
  }

  if (def.dispatchHandler) {
    (store as any)["dispatchHandler"] = def.dispatchHandler;
  }

  const _subscribeTo = {} as {
    [P in keyof Events]: (handler: (newState: State) => void) => EventBusAutoOff;
  } & {
    All: (handler: (newState: State) => void) => EventBusAutoOff;
  };

  for (const key in def.events) {
    (_subscribeTo as any)[key] = (_: any) => {
      return _this.__dispatcher.subscribe(store.id!, _, key);
    }
  }

  (_subscribeTo as any)["All"] = (_: any) => {
    return _this.__dispatcher.subscribe(store.id!, _, "ALL");
  }

  if (def.init) {
    store["init"] = def.init;
    store["init"]();
  }

  if (def.nextState) {
    store["nextState"] = def.nextState;
  }

  return {
    id          : store.id             ,
    actions     : _actions             ,
    subscribeTo : _subscribeTo         ,
    getState    : () => store["state"] ,
  }
}

export const registerStore = _registerStore.bind({ __dispatcher: new Dispatcher() });

@mjbvz mjbvz transferred this issue from microsoft/vscode Sep 4, 2020
@mjbvz
Copy link
Contributor

mjbvz commented Sep 4, 2020

Thanks!

@mjbvz mjbvz removed their assignment Sep 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants