Skip to content
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

Editor side encoding setting #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,28 @@
"onLanguage:daedalus"
],
"contributes": {
"configurationDefaults": {
"[daedalus]": {
"files.encoding": "windows1252"
}
},
"configuration": {
"type": "object",
"title": "Daedalus",
"properties": {
"daedalusLanguageServer.daedalusEncoding": {
"type": "string",
"default": "windows1252",
"enum": ["windows1250", "windows1251", "windows1252"],
"markdownEnumDescriptions": ["*Central European* (Windows 1250)" , "*Cyrillic* (Windows 1251)", "*Western* (Windows 1252)"],
"markdownDescription": "Default editor file encoding"
},
"daedalusLanguageServer.fileEncoding": {
"type": "string",
"default": "Windows-1252",
"enum": ["Windows-1250", "Windows-1251", "Windows-1252"],
"description": "The file encoding"
"description": "Server side script file encoding (`*.d` files)."
},
"daedalusLanguageServer.srcFileEncoding": {
"type": "string",
"default": "Windows-1252",
"enum": ["Windows-1250", "Windows-1251", "Windows-1252"],
"description": "The file encoding"
"description": "Server side source file encoding (`*.src` files)."
}
}
},
Expand Down
22 changes: 22 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import { Trace } from 'vscode-jsonrpc';
import { stringify } from 'querystring';
import { log } from 'console';
import { exec, execFileSync } from 'child_process';
import { ConfigurationTarget, workspace } from 'vscode';

const LANGUAGE: string = "daedalus";
interface Dictionary<T> {
[Key: string]: T;
}

const CONFIGSEC: string = "daedalusLanguageServer";

export function activate(context: vscode.ExtensionContext) {
const lspPath = path.join(context.extensionPath, 'languageserver');

Expand Down Expand Up @@ -66,6 +69,25 @@ export function activate(context: vscode.ExtensionContext) {
}
}

// On activation set settings from workspace settings (if not set from global settings)
let newSetting = workspace.getConfiguration(CONFIGSEC).get('daedalusEncoding');
log("Global or workspace encoding found on start: %s", newSetting);
workspace.getConfiguration("files").update("encoding", newSetting, false, undefined);

// Change workspace encoding setting on config change
workspace.onDidChangeConfiguration(event => {
const configurationWorkspace = workspace.getConfiguration(CONFIGSEC);

let affected = event.affectsConfiguration(CONFIGSEC);
if (affected) {
let newSetting = configurationWorkspace.get('daedalusEncoding');

log("Setting new encoding: %s", newSetting);

workspace.getConfiguration("files").update("encoding", newSetting, false, undefined);
}
})

// Create the language client and start the client.
const client = new LanguageClient('daedalusLanguageServer', 'Daedalus Language Server', serverOptions, clientOptions);
client.trace = Trace.Verbose;
Expand Down