generated from CleanroomMC/TemplateDevEnv
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Language Server fixes and improvements (#235)
* lots of changes & fixes * moving classes & stuff * custom uri decoder/encoder * dont insert . after properties * better sorting of methods and properties * classes inherit banned methods * Inline icons for Object mappers in vsc (#238) * prototype of inline icons for ObjectMapper * inline icons for ObjectMapper * fix icon uri encoding * fix icon position * fix some issues * add setting to disable icons * blacklist some mod support methods * fix weird lsp error * fix script error * fix suggesting private methods, fix signatures, fix not suggesting overloads * replace todo with comment * show last array param as varargs * only suggest public fields * add tooltips for inline icons * ban packages from groovy and lsp * fix class and member suggestions * better completion for keywords and methods * dont insert tab location on varargs * insert imports after varargs * blacklist some mixin methods * mark texture binder as experimental
- Loading branch information
Showing
64 changed files
with
2,542 additions
and
1,459 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,91 @@ | ||
import { CancellationToken, Disposable, ProviderResult, TextDocument, Range as VRange } from 'vscode'; | ||
import { ClientCapabilities, DocumentColorOptions, DocumentSelector, ensure, FeatureClient, MessageDirection, PartialResultParams, ProtocolRequestType, RequestHandler, ServerCapabilities, StaticRegistrationOptions, TextDocumentIdentifier, TextDocumentLanguageFeature, TextDocumentRegistrationOptions, WorkDoneProgressOptions, WorkDoneProgressParams } from 'vscode-languageclient'; | ||
import { registerTextureDecorationProvider } from '../languageProviders/TextureDecorationLanguageProvider'; | ||
|
||
export interface TextureDecorationParams extends WorkDoneProgressParams, PartialResultParams { | ||
/** | ||
* The text document. | ||
*/ | ||
textDocument: TextDocumentIdentifier; | ||
} | ||
|
||
export interface TextureDecorationInformation { | ||
range: VRange; | ||
textureUri: string; | ||
tooltips: string[]; | ||
} | ||
|
||
export interface TextureDecorationOptions extends WorkDoneProgressOptions { | ||
} | ||
|
||
export interface TextureDecorationRegistrationOptions extends TextDocumentRegistrationOptions, StaticRegistrationOptions, DocumentColorOptions { | ||
} | ||
|
||
export interface ProvideTextureDecorationsSignature { | ||
(document: TextDocument, token: CancellationToken): ProviderResult<TextureDecorationInformation[]>; | ||
} | ||
|
||
export interface TextureDecorationProvider { | ||
provideTextureDecoration(document: TextDocument, token: CancellationToken): ProviderResult<TextureDecorationInformation[]>; | ||
} | ||
|
||
export interface TextureDecorationMiddleware { | ||
provideTextureDecorations?: (this: void, document: TextDocument, token: CancellationToken, next: ProvideTextureDecorationsSignature) => ProviderResult<TextureDecorationInformation[]>; | ||
} | ||
|
||
export namespace TextureDecorationRequest { | ||
export const method: 'groovyScript/textureDecoration' = 'groovyScript/textureDecoration'; | ||
export const messageDirection = MessageDirection.clientToServer; | ||
export const type = new ProtocolRequestType<TextureDecorationParams, TextureDecorationInformation[], TextureDecorationInformation[], void, TextureDecorationRegistrationOptions>(method); | ||
export type HandlerSignature = RequestHandler<TextureDecorationParams, TextureDecorationInformation[], void>; | ||
} | ||
|
||
export class TextureDecorationFeature extends TextDocumentLanguageFeature<boolean | TextureDecorationOptions, TextureDecorationRegistrationOptions, TextureDecorationProvider, TextureDecorationMiddleware> { | ||
constructor(client: FeatureClient<TextureDecorationMiddleware>) { | ||
super(client, TextureDecorationRequest.type); | ||
} | ||
fillClientCapabilities(capabilities: ClientCapabilities): void { | ||
ensure(ensure(capabilities, 'experimental')!, 'textureDecorationProvider')!.dynamicRegistration = true; | ||
} | ||
initialize(capabilities: ServerCapabilities, documentSelector: DocumentSelector): void { | ||
const [id, options] = this.getRegistration(documentSelector, capabilities.experimental.textureDecorationProvider); | ||
if (!id || !options) { | ||
return; | ||
} | ||
this.register({ id: id, registerOptions: options }); | ||
} | ||
protected registerLanguageProvider(options: TextureDecorationRegistrationOptions, id: string): [Disposable, TextureDecorationProvider] { | ||
const selector = options.documentSelector!; | ||
|
||
const provider: TextureDecorationProvider = { | ||
provideTextureDecoration: (document, token) => { | ||
const client = this._client; | ||
const provideTextureDecorations: ProvideTextureDecorationsSignature = (document, token) => { | ||
const requestParams: TextureDecorationParams = { | ||
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document), | ||
}; | ||
|
||
return client.sendRequest(TextureDecorationRequest.type, requestParams, token).then((result) => { | ||
if (token.isCancellationRequested) { | ||
return null; | ||
} | ||
return result.map<TextureDecorationInformation>(decoration => ({ | ||
range: decoration.range, | ||
textureUri: client.protocol2CodeConverter.asUri(decoration.textureUri).toString(true), | ||
tooltips: decoration.tooltips | ||
})); | ||
}, (error) => { | ||
return client.handleFailedRequest(TextureDecorationRequest.type, token, error, null); | ||
}); | ||
}; | ||
const middleware = client.middleware; | ||
return middleware.provideTextureDecorations | ||
? middleware.provideTextureDecorations(document, token, provideTextureDecorations) | ||
: provideTextureDecorations(document, token); | ||
}, | ||
}; | ||
|
||
return [registerTextureDecorationProvider(this._client.protocol2CodeConverter.asDocumentSelector(selector), provider), provider]; | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
editors/vscode/src/languageProviders/TextureDecorationLanguageProvider.ts
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,66 @@ | ||
import * as vscode from "vscode"; | ||
import { DocumentSelector, Disposable, window as vWindow, workspace as vWorkspace, CancellationTokenSource, TextEditor, languages, DecorationOptions, Uri } from "vscode"; | ||
import { TextureDecorationInformation, TextureDecorationProvider } from "../features/TextureDecoration"; | ||
|
||
export function registerTextureDecorationProvider(selector: DocumentSelector, provider: TextureDecorationProvider): Disposable { | ||
let cancellationSource = new CancellationTokenSource(); | ||
|
||
function cancel() { | ||
cancellationSource.cancel(); | ||
cancellationSource.dispose(); | ||
cancellationSource = new CancellationTokenSource(); | ||
} | ||
|
||
async function doDecorate(editor: TextEditor): Promise<void> { | ||
const configuration = vscode.workspace.getConfiguration("groovyscript"); | ||
if (configuration.get<boolean>("enableIcons", true)) { | ||
const result = await provider.provideTextureDecoration(editor.document, cancellationSource.token); | ||
if (result) { | ||
decorate(editor, result); | ||
} | ||
return; | ||
} | ||
removeDecoration(editor) | ||
return; | ||
} | ||
|
||
const editorChangedHandler = async (editor: TextEditor | undefined): Promise<void> => { | ||
if (editor && languages.match(selector, editor.document)) { | ||
cancel(); | ||
await doDecorate(editor) | ||
} | ||
}; | ||
const changedActiveTextEditor = vWindow.onDidChangeActiveTextEditor(editorChangedHandler); | ||
|
||
editorChangedHandler(vWindow.activeTextEditor); | ||
|
||
const changedDocumentText = vWorkspace.onDidChangeTextDocument(async event => { | ||
if (vWindow.activeTextEditor?.document === event.document && languages.match(selector, event.document)) { | ||
cancel(); | ||
await doDecorate(vWindow.activeTextEditor) | ||
} | ||
}) | ||
|
||
return new Disposable(() => { | ||
changedActiveTextEditor.dispose(); | ||
changedDocumentText.dispose(); | ||
}); | ||
} | ||
|
||
function removeDecoration(textEditor: TextEditor) { | ||
textEditor.setDecorations(decorationStyle, []) | ||
} | ||
|
||
function decorate(textEditor: TextEditor, decorations: TextureDecorationInformation[]) { | ||
textEditor.setDecorations(decorationStyle, decorations.map<DecorationOptions>(decoration => ({ | ||
range: decoration.range, | ||
hoverMessage: decoration.tooltips, | ||
renderOptions: { | ||
before: { | ||
contentIconPath: Uri.parse(decoration.textureUri, true), | ||
} | ||
} | ||
}))) | ||
} | ||
|
||
const decorationStyle = vWindow.createTextEditorDecorationType({}) |
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
Oops, something went wrong.