Getting stuff building again, clarifying instructions on support for addional file types and language services (#30)
This commit is contained in:
Родитель
b97b023e95
Коммит
ca9b4b68f7
|
@ -1,17 +1,17 @@
|
|||
{
|
||||
"version": "0.1.0",
|
||||
// List of configurations. Add new configurations or edit existing ones.
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Attach",
|
||||
"type": "node",
|
||||
"request": "attach",
|
||||
// TCP/IP address. Default is "localhost".
|
||||
"address": "localhost",
|
||||
// Port to attach to.
|
||||
"port": 6004,
|
||||
"sourceMaps": true,
|
||||
"outDir": "${workspaceRoot}/../htmlhint/server"
|
||||
}
|
||||
]
|
||||
"version": "0.1.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Attach",
|
||||
"type": "node",
|
||||
"request": "attach",
|
||||
"address": "localhost",
|
||||
"protocol": "inspector",
|
||||
"port": 6010,
|
||||
"sourceMaps": true,
|
||||
"outFiles": [
|
||||
"${workspaceRoot}/../htmlhint/server/**/*.js"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -10,11 +10,11 @@
|
|||
"fs": "0.0.2",
|
||||
"htmlhint": "^0.9.13",
|
||||
"strip-json-comments": "^2.0.0",
|
||||
"vscode-languageserver": "^2.5.0"
|
||||
"vscode-languageserver": "^3.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^6.0.51",
|
||||
"typescript": "^2.0.10"
|
||||
"@types/node": "^6.0.41",
|
||||
"typescript": "^2.5.2"
|
||||
},
|
||||
"scripts": {
|
||||
"compile": "installServerIntoExtension ../htmlhint ./package.json ./src/tsconfig.json && node node_modules/typescript/bin/tsc -p ./src",
|
||||
|
|
|
@ -177,14 +177,14 @@ function trace(message: string, verbose?: string): void {
|
|||
connection.tracer.log(message, verbose);
|
||||
}
|
||||
|
||||
connection.onInitialize((params): Thenable<server.InitializeResult | server.ResponseError<server.InitializeError>> => {
|
||||
connection.onInitialize((params: server.InitializeParams, token: server.CancellationToken) => {
|
||||
let rootFolder = params.rootPath;
|
||||
let initOptions: {
|
||||
nodePath: string;
|
||||
} = params.initializationOptions;
|
||||
let nodePath = initOptions ? (initOptions.nodePath ? initOptions.nodePath : undefined) : undefined;
|
||||
|
||||
return server.Files.resolveModule2(rootFolder, 'htmlhint', nodePath, trace).
|
||||
const result= server.Files.resolveModule2(rootFolder, 'htmlhint', nodePath, trace).
|
||||
then((value): server.InitializeResult | server.ResponseError<server.InitializeError> => {
|
||||
linter = value.HTMLHint;
|
||||
//connection.window.showInformationMessage(`onInitialize() - found local htmlhint (version ! ${value.HTMLHint.version})`);
|
||||
|
@ -198,6 +198,8 @@ connection.onInitialize((params): Thenable<server.InitializeResult | server.Resp
|
|||
let result: server.InitializeResult = { capabilities: { textDocumentSync: documents.syncKind } };
|
||||
return result;
|
||||
});
|
||||
|
||||
return result as Thenable<server.InitializeResult>;
|
||||
});
|
||||
|
||||
function doValidate(connection: server.IConnection, document: server.TextDocument): void {
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
|
||||
"stopOnEntry": false,
|
||||
"sourceMaps": true,
|
||||
"outDir": "${workspaceRoot}/out",
|
||||
"outFiles": ["${workspaceRoot}/out/*.js"],
|
||||
"preLaunchTask": "npm"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,24 +47,52 @@ If you'd like to modify the rules, you can provide a `.htmlhintrc` file in the r
|
|||
|
||||
You can learn more about rule configuration at the HTMLHint [Usage page](https://github.com/yaniswang/HTMLHint/wiki/Usage#cli).
|
||||
|
||||
## Additional file types
|
||||
|
||||
By default, HTMLHint will run on any files associated with the "html" language service (i.e., ".html" and ".htm" files). If you'd like to use the HTMLHint extension with additional file types, you have two options:
|
||||
|
||||
### Option 1: Treating your file like any other html file
|
||||
|
||||
If you would like the file type to be treated as any other html file (including syntax highlighting, as well as HTMLHint linting), you'll need to associate the extension with the html language service. Add the following to your VS Code [settings](https://code.visualstudio.com/docs/customization/userandworkspace), replacing `"*.ext"` with your file extension.
|
||||
|
||||
```json
|
||||
{
|
||||
"files.associations": {
|
||||
"*.ext": "html",
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Option 2: Associating HTMLHint extension with your file type
|
||||
|
||||
If your file type already has an associated language service other than "html", and you'd like HTMLHint to process those file types, you will need to associate the HTMLHint extension with that language service. Add the following to your VS Code [settings](https://code.visualstudio.com/docs/customization/userandworkspace), replacing `"mylang"` with your language service. For example, if you want HTMLHint to process `.twig` files, you would use `"twig"`. Note that with this configuration, **you need to open an html file first** to activate the HTMLHint extension. Otherwise, you won't see any linter errors, (the extension is hard-coded to activate when the html language service activates).
|
||||
|
||||
```json
|
||||
{
|
||||
"htmlhint.documentSelector": [
|
||||
"html",
|
||||
"mylang"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Settings
|
||||
|
||||
The HTMLHint extension provides three [settings](https://code.visualstudio.com/docs/customization/userandworkspace):
|
||||
|
||||
* `htmlhint.enable` - disable the HTMLHint extension globally or per workspace.
|
||||
* `htmlhint.extensions` - specify additional file extensions to be linted
|
||||
* `htmlhint.documentSelector` - specify additional language services to be linted
|
||||
* `htmlhint.options` - provide a rule set to override on disk `.htmlhintrc` or HTMLHint defaults.
|
||||
|
||||
You can change settings globally (**File** > **Preferences** > **User Settings**) or per workspace (**File** > **Preferences** > **Workspace Settings**). The **Preferences** menu is under **Code** on macOS.
|
||||
|
||||
Here's an example using the `htmlhint.extensions` and `htmlhint.options` settings:
|
||||
Here's an example using the `htmlhint.documentSelector` and `htmlhint.options` settings:
|
||||
|
||||
```json
|
||||
"htmlhint.extensions: [
|
||||
"htmlhint.documentSelector: [
|
||||
"html",
|
||||
"htm",
|
||||
"twig",
|
||||
"mustache"
|
||||
"twig"
|
||||
],
|
||||
"htmlhint.options": {
|
||||
"tagname-lowercase": false,
|
||||
|
@ -73,3 +101,5 @@ Here's an example using the `htmlhint.extensions` and `htmlhint.options` setting
|
|||
"doctype-first": true
|
||||
}
|
||||
```
|
||||
|
||||
Note that in order to have the linter apply to addi
|
|
@ -7,7 +7,7 @@ export function activate(context: ExtensionContext) {
|
|||
// We need to go one level up since an extension compile the js code into
|
||||
// the output folder.
|
||||
let serverModulePath = path.join(__dirname, '..', 'server', 'server.js');
|
||||
let debugOptions = { execArgv: ["--nolazy", "--debug=6004"] };
|
||||
let debugOptions = { execArgv: ["--nolazy", "--inspect=6010"], cwd: process.cwd() };
|
||||
let serverOptions: ServerOptions = {
|
||||
run: { module: serverModulePath },
|
||||
debug: { module: serverModulePath, options: debugOptions }
|
||||
|
@ -15,8 +15,8 @@ export function activate(context: ExtensionContext) {
|
|||
|
||||
// Get file types to lint from user settings
|
||||
let config = workspace.getConfiguration('htmlhint');
|
||||
let extensions = config.get('extensions');
|
||||
|
||||
let extensions = config.get('documentSelector') as string[];
|
||||
|
||||
// Set options
|
||||
let clientOptions: LanguageClientOptions = {
|
||||
documentSelector: extensions,
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
"Linters"
|
||||
],
|
||||
"engines": {
|
||||
"vscode": "^1.4.0"
|
||||
"vscode": "^1.16.0"
|
||||
},
|
||||
"activationEvents": [
|
||||
"onLanguage:html"
|
||||
|
@ -40,10 +40,10 @@
|
|||
"default": true,
|
||||
"description": "Control whether htmlhint is enabled for HTML files or not."
|
||||
},
|
||||
"htmlhint.extensions": {
|
||||
"htmlhint.documentSelector": {
|
||||
"type": "array",
|
||||
"default": ["html", "htm"],
|
||||
"description": "The file extensions to be linted."
|
||||
"description": "The associated document types to be linted."
|
||||
},
|
||||
"htmlhint.options": {
|
||||
"type": "object",
|
||||
|
@ -55,15 +55,16 @@
|
|||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "node ./node_modules/typescript/bin/tsc -p ./",
|
||||
"compile": "node ./node_modules/typescript/bin/tsc -watch -p ./",
|
||||
"compile": "node ./node_modules/typescript/bin/tsc -p ./",
|
||||
"watch": "node ./node_modules/typescript/bin/tsc -watch -p ./",
|
||||
"postinstall": "node ./node_modules/vscode/bin/install"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^6.0.41",
|
||||
"typescript": "^2.0.10",
|
||||
"vscode": "^1.0.3"
|
||||
"typescript": "^2.5.2",
|
||||
"vscode": "^1.1.5",
|
||||
"@types/node": "^6.0.41"
|
||||
},
|
||||
"dependencies": {
|
||||
"vscode-languageclient": "^2.6.3"
|
||||
"vscode-languageclient": "^3.4.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,11 +6,10 @@
|
|||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"sourceMap": true,
|
||||
"rootDir": "."
|
||||
"sourceMap": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
".vscode-test"
|
||||
"server"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"files.associations": {
|
||||
"*.x": "html"
|
||||
},
|
||||
"htmlhint.documentSelector": [
|
||||
"html",
|
||||
"x"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
<!--<!DOCTYPE html>-->
|
||||
<ul>
|
||||
<li>
|
||||
<a href='http://www.github.com'>github</a>
|
||||
</ul>
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
<!--<!DOCTYPE html>-->
|
||||
<ul>
|
||||
<li>
|
||||
<a href='http://www.github.com'>github</a>
|
||||
</ul>
|
Загрузка…
Ссылка в новой задаче