I am developing a visual studio code simple extension in which I want to change sass file color provider to be same as the one of a css file I have done
vscode.languages.registerColorProvider(DocumentSelector, DocumentColorProvider);
but I am not familiar with the DocumentColorProvider api and I have declare my DocumentSelector like this:
let sel: vscode.DocumentSelector = { scheme: 'file', language: 'sass' };
in which I am trying to give a color provider to a sass file
but I haven't been able to declare the DocumentColorProvider I am not sure how to deal with it, is it a class? an interface? a hash?, I have read the Documentation and the API Documentation but still no clue how to do it
How Do I declare a DocumentColorProvider and the provideDocumentColors and provideColorPresentations inside the DocumentColorProvider?
also I have done this based in the typescript example of the Hello World Extension
The DocumentColorProvider creates a color palette in the editor for you to select a specific color. similar to what happens in the CSS file when typing "background-color: red"[X] -> Opens a color picker!
Below is an example of how to use DocumentColorProvider:
vscode.languages.registerColorProvider({language: 'html', scheme: 'file', pattern: '**/*.scss'}, { provideColorPresentations(color, context, token) { let newColor = [new vscode.ColorPresentation('My Color Pallet')]; return newColor; }, provideDocumentColors(document, token){ const positionStart = new vscode.Position(0, 5); const positionEnd = new vscode.Position(8, 5); const range = new vscode.Range(positionStart, positionEnd); const color = new vscode.Color(0, 0, 255, 0.2); return [new vscode.ColorInformation(range, color)]; } });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.