-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes TypeFox/Theia#54: LanguageClientContribution
- Loading branch information
Showing
27 changed files
with
638 additions
and
137 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
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
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
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,18 @@ | ||
|
||
/* | ||
* Copyright (C) 2017 TypeFox and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
import { ContainerModule } from "inversify"; | ||
import { ResourceResolver } from '../../application/common'; | ||
import { JavaClientContribution } from "./java-client-contribution"; | ||
import { LanguageClientContribution } from "../../languages/browser"; | ||
|
||
export const browserJavaModule = new ContainerModule(bind => { | ||
bind(JavaClientContribution).toSelf().inSingletonScope(); | ||
bind(ResourceResolver).toDynamicValue(ctx => ctx.container.get(JavaClientContribution)); | ||
bind(LanguageClientContribution).toDynamicValue(ctx => ctx.container.get(JavaClientContribution)); | ||
}); |
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,12 @@ | ||
/* | ||
* Copyright (C) 2017 TypeFox and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
export * from '../common'; | ||
export * from './java-protocol'; | ||
export * from './java-resource'; | ||
export * from './java-client-contribution'; | ||
export * from './browser-java-module'; |
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,59 @@ | ||
/* | ||
* Copyright (C) 2017 TypeFox and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
import { injectable } from "inversify"; | ||
import { ResourceResolver, DisposableCollection } from "../../application/common"; | ||
import URI from "../../application/common/uri"; | ||
import { ILanguageClient, LanguageIdentifier, LanguageClientContribution } from '../../languages/browser'; | ||
import { JAVA_LANGUAGE_ID } from '../common'; | ||
import { JavaResource } from "./java-resource"; | ||
|
||
@injectable() | ||
export class JavaClientContribution implements ResourceResolver, LanguageClientContribution { | ||
|
||
protected languageClient: ILanguageClient | undefined; | ||
|
||
protected resolveDidStart: (languageClient: ILanguageClient) => void; | ||
protected didStart: Promise<ILanguageClient>; | ||
|
||
protected readonly toDisposeOnWillStart = new DisposableCollection(); | ||
|
||
constructor() { | ||
this.waitForDidStart(); | ||
} | ||
|
||
resolve(uri: URI): Promise<JavaResource> { | ||
const resolveLanguageClient = this.resolveLanguageClient.bind(this); | ||
const javaResource = new JavaResource(uri, resolveLanguageClient); | ||
return Promise.resolve(javaResource); | ||
} | ||
|
||
protected resolveLanguageClient(): Promise<ILanguageClient> { | ||
return this.languageClient ? Promise.resolve(this.languageClient) : this.didStart; | ||
} | ||
|
||
onWillStart(language: LanguageIdentifier, languageClient: ILanguageClient): void { | ||
if (language.description.id === JAVA_LANGUAGE_ID) { | ||
languageClient.onReady().then(() => | ||
this.onDidStart(language, languageClient) | ||
); | ||
} | ||
} | ||
|
||
protected onDidStart(language: LanguageIdentifier, languageClient: ILanguageClient): void { | ||
this.languageClient = languageClient | ||
this.resolveDidStart(this.languageClient); | ||
this.waitForDidStart(); | ||
} | ||
|
||
protected waitForDidStart(): void { | ||
this.didStart = new Promise<ILanguageClient>(resolve => | ||
this.resolveDidStart = resolve | ||
); | ||
} | ||
|
||
} |
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,13 @@ | ||
/* | ||
* Copyright (C) 2017 TypeFox and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
import { RequestType } from 'vscode-jsonrpc'; | ||
import { TextDocumentIdentifier } from "../../languages/common"; | ||
|
||
export namespace ClassFileContentsRequest { | ||
export const type = new RequestType<TextDocumentIdentifier, string | undefined, void, void>('java/classFileContents'); | ||
} |
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,29 @@ | ||
/* | ||
* Copyright (C) 2017 TypeFox and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
import { Resource } from "../../application/common"; | ||
import URI from "../../application/common/uri"; | ||
import { ILanguageClient } from "../../languages/browser"; | ||
import { ClassFileContentsRequest } from "./java-protocol"; | ||
|
||
export class JavaResource implements Resource { | ||
|
||
constructor( | ||
public uri: URI, | ||
protected readonly resolveLanguageClient: () => Promise<ILanguageClient> | ||
) { } | ||
|
||
readContents(options: { encoding?: string }): Promise<string> { | ||
const uri = this.uri.toString(); | ||
return this.resolveLanguageClient().then(languageClient => | ||
languageClient.sendRequest(ClassFileContentsRequest.type, { uri }).then(content => | ||
content || '' | ||
) | ||
); | ||
} | ||
|
||
} |
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 @@ | ||
/* | ||
* Copyright (C) 2017 TypeFox and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
import { JAVA_LANGUAGE_ID } from '../../common'; | ||
import { configuration, monarchLanguage } from "./java-monaco-language"; | ||
|
||
monaco.languages.register({ | ||
id: JAVA_LANGUAGE_ID, | ||
extensions: ['.java', '.jav', '.class'], | ||
aliases: ['Java', 'java'], | ||
mimetypes: ['text/x-java-source', 'text/x-java'], | ||
}); | ||
|
||
monaco.languages.onLanguage(JAVA_LANGUAGE_ID, () => { | ||
monaco.languages.setLanguageConfiguration(JAVA_LANGUAGE_ID, configuration); | ||
monaco.languages.setMonarchTokensProvider(JAVA_LANGUAGE_ID, monarchLanguage); | ||
}); |
Oops, something went wrong.