[html] add razor

This commit is contained in:
Martin Aeschlimann 2016-09-14 16:39:14 +02:00
parent 21c9ad57a6
commit 2a4e5b023d
13 changed files with 1545 additions and 962 deletions

View file

@ -30,7 +30,7 @@ export function activate(context: ExtensionContext) {
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for json documents
documentSelector: ['html', 'handlebars'],
documentSelector: ['html', 'handlebars', 'razor'],
synchronize: {
// Synchronize the setting section 'html' to the server
configurationSection: ['html'],

View file

@ -7,7 +7,8 @@
},
"activationEvents": [
"onLanguage:html",
"onLanguage:handlebars"
"onLanguage:handlebars",
"onLanguage:razor"
],
"main": "./client/out/htmlMain",
"scripts": {
@ -83,6 +84,21 @@
],
"default": "head, body, /html",
"description": "List of tags, comma separated, that should have an extra newline before them. 'null' defaults to \"head, body, /html\"."
},
"html.suggest.angular1": {
"type": "boolean",
"default": true,
"description": "Configures if the built-in HTML language support suggests Angular V1 tags and properties."
},
"html.suggest.ionic": {
"type": "boolean",
"default": true,
"description": "Configures if the built-in HTML language support suggests Ionic tags, properties and values."
},
"html.suggest.html5": {
"type": "boolean",
"default": true,
"description": "Configures if the built-in HTML language support suggests HTML5 tags, properties and values."
}
}
}

View file

@ -0,0 +1,39 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import {IHTMLTagProvider} from './htmlTags';
export function getRazorTagProvider() : IHTMLTagProvider {
var customTags : { [tag:string]: string[]} = {
a: ['asp-action', 'asp-controller', 'asp-fragment', 'asp-host', 'asp-protocol', 'asp-route'],
div: ['asp-validation-summary'],
form: ['asp-action', 'asp-controller', 'asp-anti-forgery'],
input: ['asp-for', 'asp-format'],
label: ['asp-for'],
select: ['asp-for', 'asp-items'],
span: ['asp-validation-for']
};
return {
getId: () => 'razor',
isApplicable: (languageId) => languageId === 'razor',
collectTags: (collector: (tag: string) => void) => {
// no extra tags
},
collectAttributes: (tag: string, collector: (attribute: string, type: string) => void) => {
if (tag) {
var attributes = customTags[tag];
if (attributes) {
attributes.forEach(a => collector(a, null));
}
}
},
collectValues: (tag: string, attribute: string, collector: (value: string) => void) => {
// no values
}
};
}

View file

@ -8,12 +8,14 @@ import { TextDocument, Position, CompletionList, CompletionItemKind, Range } fro
import { HTMLDocument } from '../parser/htmlParser';
import { TokenType, createScanner, ScannerState } from '../parser/htmlScanner';
import { getHTML5TagProvider, getAngularTagProvider, getIonicTagProvider } from '../parser/htmlTags';
import { getRazorTagProvider } from '../parser/razorTags';
import { CompletionConfiguration } from '../htmlLanguageService';
let allTagProviders = [
getHTML5TagProvider(),
getAngularTagProvider(),
getIonicTagProvider()
getIonicTagProvider(),
getRazorTagProvider()
];
export function doComplete(document: TextDocument, position: Position, doc: HTMLDocument, settings?: CompletionConfiguration): CompletionList {

View file

@ -0,0 +1,7 @@
// ATTENTION - THIS DIRECTORY CONTAINS THIRD PARTY OPEN SOURCE MATERIALS:
[{
"name": "demyte/language-cshtml",
"version": "0.0.0",
"license": "MIT",
"repositoryURL": "https://github.com/demyte/language-cshtml"
}]

View file

@ -0,0 +1,24 @@
{
"comments": {
"blockComment": [ "<!--", "-->" ]
},
"brackets": [
["<!--", "-->"],
["<", ">"],
["{", "}"],
["(", ")"]
],
"autoClosingPairs": [
{ "open": "{", "close": "}"},
{ "open": "[", "close": "]"},
{ "open": "(", "close": ")" },
{ "open": "'", "close": "'" },
{ "open": "\"", "close": "\"" },
{ "open": "<", "close": ">" }
],
"surroundingPairs": [
{ "open": "'", "close": "'" },
{ "open": "\"", "close": "\"" },
{ "open": "<", "close": ">" }
]
}

View file

@ -0,0 +1,24 @@
{
"name": "razor",
"version": "0.1.0",
"publisher": "vscode",
"engines": {
"vscode": "0.10.x"
},
"scripts": {
"update-grammar": "node ../../build/npm/update-grammar.js demyte/language-cshtml grammars/cshtml.cson ./syntaxes/cshtml.json"
},
"contributes": {
"languages": [{
"id": "razor",
"extensions": [ ".cshtml"],
"aliases": [ "Razor", "razor" ],
"mimetypes": ["text/x-cshtml"]
}],
"grammars": [{
"language": "razor",
"scopeName": "text.html.cshtml",
"path": "./syntaxes/cshtml.json"
}]
}
}

View file

@ -0,0 +1,153 @@
{
"name": "ASP.NET Razor",
"scopeName": "text.html.cshtml",
"fileTypes": [
"cshtml",
"gohtml"
],
"patterns": [
{
"name": "section.embedded.source.cshtml",
"begin": "(@?([a-zA-Z0-9]+)?)(\\s[a-zA-Z0-9]+)?(\n|\r)?(\\{)",
"beginCaptures": {
"0": {
"name": "punctuation.section.embedded.begin.cshtml"
},
"1": {
"name": "keyword.control.cshtml"
}
},
"patterns": [
{
"name": "section.embedded.source.cshtml",
"begin": "(@?([a-zA-Z0-9]+)?)(\\s[a-zA-Z0-9]+)?(\n|\r)?(\\{)",
"beginCaptures": {
"0": {
"name": "punctuation.section.embedded.begin.cshtml"
},
"1": {
"name": "keyword.control.cshtml"
}
},
"patterns": [
{
"name": "string.quoted.single.cshtml",
"match": "'"
},
{
"include": "#embedded-code"
},
{
"include": "#comments"
},
{
"include": "source.cs"
},
{
"include": "text.html.basic"
}
],
"end": "\\}",
"endCaptures": {
"0": {
"name": "punctuation.section.embedded.begin.cshtml"
}
}
},
{
"name": "string.quoted.single.cshtml",
"match": "'"
},
{
"include": "#embedded-code"
},
{
"include": "#comments"
},
{
"include": "text.html.basic"
}
],
"end": "\\}",
"endCaptures": {
"0": {
"name": "punctuation.section.embedded.begin.cshtml"
}
},
"comments": "Simple multi-line code section"
},
{
"begin": "(@[a-zA-Z0-9]+)(\\s?)",
"captures": {
"0": {
"name": "section.embedded.begin.cshtml"
},
"1": {
"name": "keyword.control.cshtml"
}
},
"patterns": [
{
"match": "(([a-zA-Z0-9]+)(\\.)?)+?",
"captures": {
"2": {
"name": "entity.name.tag.source.cshtml"
},
"3": {
"name": "punctuation.separator.namespace.source.cshtml"
}
}
},
{
"include": "#embedded-code"
},
{
"include": "#comments"
},
{
"include": "source.cs"
},
{
"include": "text.html.basic"
}
],
"end": "(\\n|\\s)",
"comments": "Covers single line Razor tags"
},
{
"include": "#comments"
},
{
"include": "text.html.basic"
}
],
"repository": {
"embedded-code": {
"match": "(@?[a-zA-Z0-9]+)(\\.([a-zA-Z0-9]+))?",
"captures": {
"1": {
"name": "keyword.control.cshtml"
},
"3": {
"name": "entity.name.tag.source.cshtml"
}
},
"patterns": [
{
"include": "#comments"
}
]
},
"comments": {
"begin": "@\\*",
"captures": {
"0": {
"name": "punctuation.definition.comment.source.cshtml"
}
},
"end": "\\*@",
"name": "comment.block.cshtml"
}
},
"version": "https://github.com/demyte/language-cshtml/commit/a49735dc7aef56ae772a3bcfd8e42c89895dcff4"
}

View file

@ -9,10 +9,10 @@ import 'vs/editor/browser/editor.all';
import 'vs/editor/contrib/quickOpen/browser/quickOutline';
import 'vs/editor/contrib/quickOpen/browser/gotoLine';
import 'vs/editor/contrib/quickOpen/browser/quickCommand';
import 'vs/languages/languages.main';
import 'vs/languages/php/common/php.contribution';
import 'vs/languages/html/common/html.contribution';
import 'vs/languages/handlebars/common/handlebars.contribution';
import 'vs/languages/razor/common/razor.contribution';
import {createMonacoBaseAPI} from 'vs/editor/common/standalone/standaloneBase';
import {createMonacoEditorAPI} from 'vs/editor/browser/standalone/standaloneEditor';

View file

@ -1,9 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import 'vs/languages/razor/common/razor.contribution';

View file

@ -16,9 +16,6 @@ import 'vs/editor/contrib/selectionClipboard/electron-browser/selectionClipboard
import 'vs/editor/contrib/suggest/electron-browser/snippetCompletion';
import 'vs/editor/browser/editor.all';
// Languages
import 'vs/languages/languages.main';
// Menus/Actions
import 'vs/platform/actions/browser/menusExtensionPoint';