-
Notifications
You must be signed in to change notification settings - Fork 12
/
configuration.ts
120 lines (93 loc) · 3.6 KB
/
configuration.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'use strict';
import * as vscode from 'vscode';
import { platform } from 'os';
import { join } from 'path';
import { each, isNull } from 'lodash';
import { existsSync } from 'fs';
export class ConfigManager {
private static _instance: ConfigManager = new ConfigManager();
private config: { [key: string]: any } = {};
constructor() {
if (ConfigManager._instance) {
throw new Error("Error: Instantiation failed: Use ConfigManager.getInstance() instead of new.");
}
ConfigManager._instance = this;
}
public static getInstance(): ConfigManager {
return ConfigManager._instance;
}
public getConfig(): { [key: string]: any } {
return this.config;
}
private findCpplintPath(settings: vscode.WorkspaceConfiguration): string {
let cpplintPath = settings.get('cpplintPath', null);
if (isNull(cpplintPath)) {
let p = platform();
if (p === 'win32') {
// TODO: add win32 and win64 cpplint path
}
else if (p === 'linux' || p === 'darwin') {
let attempts = ['/usr/local/bin/cpplint'];
for (let index = 0; index < attempts.length; index++) {
if (existsSync(attempts[index])) {
cpplintPath = attempts[index];
break;
}
}
}
}
return cpplintPath;
}
public isSingleMode(): boolean {
if (this.config['lintMode'] == 'single') {
return true;
} else {
return false;
}
}
public isSupportLanguage(language: string): boolean {
if (this.config["languages"].indexOf(language) >= 0) {
return true;
} else {
return false;
}
}
public initialize() {
this.config = {};
let settings = vscode.workspace.getConfiguration('cpplint');
if (settings) {
var cpplintPath = this.findCpplintPath(settings);
if (!existsSync(cpplintPath)) {
vscode.window.showErrorMessage('Cpplint: Could not find cpplint executable');
}
this.config['cpplintPath'] = cpplintPath;
var linelength = settings.get("lineLength", 80);
this.config['lineLength'] = linelength;
var lintmode = settings.get('lintMode', 'single');
this.config['lintMode'] = lintmode;
var excludes = settings.get('excludes', [])
this.config['excludes'] = excludes;
var filters = settings.get("filters", [])
this.config["filters"] = filters;
var root = settings.get("root", "")
this.config["root"] = root;
var languages = settings.get("languages", [])
this.config["languages"] = languages;
var extensions = settings.get("extensions", "")
this.config["extensions"] = extensions;
var headers = settings.get("headers", "")
this.config["headers"] = headers;
var repository = settings.get("repository", "")
this.config["repository"] = repository;
this.config["filters"].forEach(element => {
if (element[0] != '-' && element[0] != '+') {
vscode.window.showErrorMessage("filter [" + element + '] must start with + or -, please check your settings');
return false;
}
});
var verbose = settings.get("verbose", 0)
this.config['verbose'] = verbose;
}
return this.config;
}
}