Skip to content
This repository was archived by the owner on Apr 8, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"publisher": "mrmlnc",
"license": "MIT",
"engines": {
"vscode": "^1.15.0"
"vscode": "^1.16.0"
},
"icon": "icon.png",
"author": {
Expand Down
22 changes: 18 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,19 @@ function getProvider(document: vscode.TextDocument, selection: vscode.Selection,

export function activate(context: vscode.ExtensionContext) {
const onCommand = vscode.commands.registerTextEditorCommand('csscomb.execute', (textEditor) => {
// Prevent run command without active TextEditor
if (!vscode.window.activeTextEditor) {
return null;
}

const document = textEditor.document;
const selection = textEditor.selection;
const filepath = document.uri.fsPath;
const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
const workspace = workspaceFolder.uri.fsPath;
const settings = vscode.workspace.getConfiguration('csscomb', workspaceFolder.uri) as IPluginSettings;
// Use workspace directory or filepath of current file as workspace folder
const workspace = workspaceFolder ? workspaceFolder.uri.fsPath : filepath;
const workspaceUri = workspaceFolder ? workspaceFolder.uri : null;
const settings = vscode.workspace.getConfiguration('csscomb', workspaceUri) as IPluginSettings;

const provider = getProvider(document, selection, workspace, filepath, settings);

Expand All @@ -66,11 +73,18 @@ export function activate(context: vscode.ExtensionContext) {
});

const onSave = vscode.workspace.onWillSaveTextDocument((event) => {
// Prevent run command without active TextEditor
if (!vscode.window.activeTextEditor) {
return null;
}

const document = event.document;
const filepath = document.uri.fsPath;
const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
const workspace = workspaceFolder.uri.fsPath;
const settings = vscode.workspace.getConfiguration('csscomb', workspaceFolder.uri) as IPluginSettings;
// Use workspace directory or filepath of current file as workspace folder
const workspace = workspaceFolder ? workspaceFolder.uri.fsPath : filepath;
const workspaceUri = workspaceFolder ? workspaceFolder.uri : null;
const settings = vscode.workspace.getConfiguration('csscomb', workspaceUri) as IPluginSettings;

// Skip files without providers
const provider = getProvider(document, null, workspace, filepath, settings);
Expand Down
8 changes: 4 additions & 4 deletions src/providers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ const configProfiler = new ConfigProfiler(null, {

export default class BaseProvider {
constructor(
private workspace: string,
private filepath: string,
public syntax: string,
private settings: IPluginSettings
private readonly workspace: string,
private readonly filepath: string,
public readonly syntax: string,
private readonly settings: IPluginSettings
) { }

public supportedSyntaxes(): string[] {
Expand Down
4 changes: 2 additions & 2 deletions src/providers/embedded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export interface IStyleBlock {

export default class EmbeddedProvider extends BaseProvider {
constructor(
private document: vscode.TextDocument,
public syntax: string,
private readonly document: vscode.TextDocument,
public readonly syntax: string,
workspace: string, filepath: string, settings: IPluginSettings
) {
super(workspace, filepath, syntax, settings);
Expand Down
6 changes: 3 additions & 3 deletions src/providers/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { IPluginSettings, IStyleBlock } from '../types';

export default class StylesProvider extends BaseProvider {
constructor(
private document: vscode.TextDocument,
private selection: vscode.Selection,
public syntax: string,
private readonly document: vscode.TextDocument,
private readonly selection: vscode.Selection,
public readonly syntax: string,
workspace: string, filepath: string, settings: IPluginSettings
) {
super(workspace, filepath, syntax, settings);
Expand Down