<file_sep>import { CommandContribution } from "@theia/core";
import { ContainerModule } from "inversify";
import { MyService, MyServicePath } from "../common/protocol";
import { MyserviceCommandContribution } from "./extension.contribution";
import {WebSocketConnectionProvider} from '@theia/core/lib/browser'
export default new ContainerModule(bind => {
	//register new widget (literally sidebar button)
	// bind(FrontendApplicationContribution).toService(MyserviceCommandContribution)
	bind(CommandContribution).to(MyserviceCommandContribution).inSingletonScope()
	bind(MyService).toDynamicValue(ctx => {
		const Connection = ctx.container.get(WebSocketConnectionProvider)
		return Connection.createProxy<MyService>(MyServicePath)
		}).inSingletonScope()
})<file_sep>
export const MyServicePath = '/serveices/my-services'
export const MyService = Symbol('MyService')

export interface MyService {
	getNameString(name:string) : Promise<string>
	//表明的是返回一个promise类型的字符串

}<file_sep>import { inject,injectable } from "inversify";
import { CommandContribution ,CommandRegistry,MessageService,Command} from "@theia/core";

import { MyService } from "../common/protocol"
export const MyExtensionCommand:Command = {
	id:"MyExtension.command",
	label:"my extension"
}

@injectable()
export class MyserviceCommandContribution implements CommandContribution {
	constructor(
		@inject(MyService) protected readonly myServiceBackend: MyService,
		@inject(MessageService) protected readonly messageService: MessageService
	){}
	registerCommands(registry:CommandRegistry):void{
		registry.registerCommand(MyExtensionCommand,{
			execute:() => {
				// await this.messageService.info('setting')
				//下面这个setting没回来
				//前端拿不到后端的东西
				console.log("start")
				debugger
				this.myServiceBackend.getNameString("world")
				.then( res => {console.log(res)})
				.catch(err => {throw new Error("cuowu")})
			}
		})
	}
} <file_sep>/**
 * Generated using theia-extension-generator
 */
import { LabelProviderContribution} from "@theia/core/lib/browser";
import { CommandContribution} from "@theia/core/lib/common";
import { ContainerModule } from "inversify";
import { TheiaExtLabelProviderContribution,TheiaExtensionCommandContribution } from './theia-ext-contribution';
import '../../src/browser/style/example.css';

export default new ContainerModule(bind => {
    bind(LabelProviderContribution).to(TheiaExtLabelProviderContribution);
    bind(CommandContribution).to(TheiaExtensionCommandContribution);
});
<file_sep>import { ContainerModule } from "inversify";
import { ConnectionHandler,JsonRpcConnectionHandler } from "@theia/core";
import { MyService ,MyServicePath} from "../common/protocol";
import { MyserviceBackend } from "./serviceBackend";


export default new ContainerModule(bind => {
	bind(MyserviceBackend).toSelf()
	bind(MyService).toService(MyserviceBackend)
	bind(ConnectionHandler).toDynamicValue(ctx => new JsonRpcConnectionHandler(MyServicePath,() => ctx.container.get<MyService>(MyService))).inSingletonScope()
})<file_sep>import { injectable } from "inversify";
import { MyService } from '../common/protocol'

@injectable()
export class MyserviceBackend implements MyService {
	getNameString(name:string):Promise<string>{
		return new Promise<string>(resolve => resolve('Hello' + name))
	}
}<file_sep>import { FileStatNode } from "@theia/filesystem/lib/browser/file-tree/file-tree";
import { FileTreeLabelProvider } from "@theia/filesystem/lib/browser/file-tree/file-tree-label-provider";
import { injectable, inject } from "inversify";
import { CommandContribution, CommandRegistry, MessageService  } from "@theia/core/lib/common";
/**
 * 这个是创建的文件前面的符号表示
 */
@injectable()
export class TheiaExtLabelProviderContribution extends FileTreeLabelProvider {
    
    canHandle(element: object): number {
        if (FileStatNode.is(element)) {
            let uri = element.uri;
            if (uri.path.ext === '.my') {
                return super.canHandle(element)+1;
            }
        }
        return 0;
    }

    getIcon(): string {
        return 'fa fa-star-o';
    }

    getName(fileStatNode: FileStatNode): string {
        return super.getName(fileStatNode) + ' (with my label)';
    }
}
export const TheiaExtensionCommand = {
    id:"HelloWorld.extension",
    label:"zhoujing"
}
@injectable()
export class TheiaExtensionCommandContribution implements CommandContribution {
    constructor(
         @inject(MessageService) private readonly messageservice:MessageService
    ){}
    registerCommands(registry:CommandRegistry): void{
        registry.registerCommand(TheiaExtensionCommand ,{
            execute:() => this.messageservice.info('大笨猪')
        })
    }
}<file_sep># theia-Json-rpc
