-
Notifications
You must be signed in to change notification settings - Fork 182
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
Organize Static Features #1073
Merged
Merged
Organize Static Features #1073
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { BaseLanguageClient, ClientCapabilities, ServerCapabilities, StaticFeature } from 'vscode-languageclient'; | ||
|
||
export interface PartialManifest { | ||
contributes: { | ||
semanticTokenTypes?: ObjectWithId[]; | ||
semanticTokenModifiers?: ObjectWithId[]; | ||
}; | ||
} | ||
|
||
interface ObjectWithId { | ||
id: string; | ||
} | ||
|
||
export class CustomSemanticTokens implements StaticFeature { | ||
constructor(private _client: BaseLanguageClient, private manifest: PartialManifest) {} | ||
|
||
public fillClientCapabilities(capabilities: ClientCapabilities): void { | ||
if (!capabilities.textDocument || !capabilities.textDocument.semanticTokens) { | ||
return; | ||
} | ||
|
||
const extSemanticTokenTypes = this.tokenTypesFromExtManifest(this.manifest); | ||
const extSemanticTokenModifiers = this.tokenModifiersFromExtManifest(this.manifest); | ||
|
||
const tokenTypes = capabilities.textDocument.semanticTokens.tokenTypes; | ||
capabilities.textDocument.semanticTokens.tokenTypes = tokenTypes.concat(extSemanticTokenTypes); | ||
|
||
const tokenModifiers = capabilities.textDocument.semanticTokens.tokenModifiers; | ||
capabilities.textDocument.semanticTokens.tokenModifiers = tokenModifiers.concat(extSemanticTokenModifiers); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
public initialize(capabilities: ServerCapabilities): void { | ||
return; | ||
} | ||
|
||
public dispose(): void { | ||
return; | ||
} | ||
|
||
tokenTypesFromExtManifest(manifest: PartialManifest): string[] { | ||
if (!manifest.contributes.semanticTokenTypes) { | ||
return []; | ||
} | ||
return manifest.contributes.semanticTokenTypes.map((token: ObjectWithId) => token.id); | ||
} | ||
|
||
tokenModifiersFromExtManifest(manifest: PartialManifest): string[] { | ||
if (!manifest.contributes.semanticTokenModifiers) { | ||
return []; | ||
} | ||
|
||
return manifest.contributes.semanticTokenModifiers.map((modifier: ObjectWithId) => modifier.id); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is now used outside the scope of semantic tokens I wonder if it's worth calling it e.g.
ManifestWithSemanticTokens
? or making a copy of that interface here which can be expanded and used elsewhere later - presumably one that is compatible withPartialManifest
withinsemanticTokens
.I suppose there are other places where we access the manifest for some other properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would agree if we didn't have more work to break up the dependencies inside ClientHandler.
ClientHandler only needs to know about this because of the StaticHandler registrations. Building up a StaticHandler should be done outside ClientHandler and passed in rather than passing in all information required to build several StaticHandlers.
I could do this here now, or do that work with the next planned PR for refactoring ClientHandler. I prefer to make those changes in the next PR.