Skip to content

Commit 2a4e5b0

Browse files
committed
[html] add razor
1 parent 21c9ad5 commit 2a4e5b0

13 files changed

Lines changed: 1327 additions & 744 deletions

File tree

extensions/html/client/src/htmlMain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function activate(context: ExtensionContext) {
3030
// Options to control the language client
3131
let clientOptions: LanguageClientOptions = {
3232
// Register the server for json documents
33-
documentSelector: ['html', 'handlebars'],
33+
documentSelector: ['html', 'handlebars', 'razor'],
3434
synchronize: {
3535
// Synchronize the setting section 'html' to the server
3636
configurationSection: ['html'],

extensions/html/package.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
},
88
"activationEvents": [
99
"onLanguage:html",
10-
"onLanguage:handlebars"
10+
"onLanguage:handlebars",
11+
"onLanguage:razor"
1112
],
1213
"main": "./client/out/htmlMain",
1314
"scripts": {
@@ -83,6 +84,21 @@
8384
],
8485
"default": "head, body, /html",
8586
"description": "List of tags, comma separated, that should have an extra newline before them. 'null' defaults to \"head, body, /html\"."
87+
},
88+
"html.suggest.angular1": {
89+
"type": "boolean",
90+
"default": true,
91+
"description": "Configures if the built-in HTML language support suggests Angular V1 tags and properties."
92+
},
93+
"html.suggest.ionic": {
94+
"type": "boolean",
95+
"default": true,
96+
"description": "Configures if the built-in HTML language support suggests Ionic tags, properties and values."
97+
},
98+
"html.suggest.html5": {
99+
"type": "boolean",
100+
"default": true,
101+
"description": "Configures if the built-in HTML language support suggests HTML5 tags, properties and values."
86102
}
87103
}
88104
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
'use strict';
6+
7+
import {IHTMLTagProvider} from './htmlTags';
8+
9+
10+
export function getRazorTagProvider() : IHTMLTagProvider {
11+
var customTags : { [tag:string]: string[]} = {
12+
a: ['asp-action', 'asp-controller', 'asp-fragment', 'asp-host', 'asp-protocol', 'asp-route'],
13+
div: ['asp-validation-summary'],
14+
form: ['asp-action', 'asp-controller', 'asp-anti-forgery'],
15+
input: ['asp-for', 'asp-format'],
16+
label: ['asp-for'],
17+
select: ['asp-for', 'asp-items'],
18+
span: ['asp-validation-for']
19+
};
20+
21+
return {
22+
getId: () => 'razor',
23+
isApplicable: (languageId) => languageId === 'razor',
24+
collectTags: (collector: (tag: string) => void) => {
25+
// no extra tags
26+
},
27+
collectAttributes: (tag: string, collector: (attribute: string, type: string) => void) => {
28+
if (tag) {
29+
var attributes = customTags[tag];
30+
if (attributes) {
31+
attributes.forEach(a => collector(a, null));
32+
}
33+
}
34+
},
35+
collectValues: (tag: string, attribute: string, collector: (value: string) => void) => {
36+
// no values
37+
}
38+
};
39+
}

extensions/html/server/src/service/services/htmlCompletion.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import { TextDocument, Position, CompletionList, CompletionItemKind, Range } fro
88
import { HTMLDocument } from '../parser/htmlParser';
99
import { TokenType, createScanner, ScannerState } from '../parser/htmlScanner';
1010
import { getHTML5TagProvider, getAngularTagProvider, getIonicTagProvider } from '../parser/htmlTags';
11+
import { getRazorTagProvider } from '../parser/razorTags';
1112
import { CompletionConfiguration } from '../htmlLanguageService';
1213

1314
let allTagProviders = [
1415
getHTML5TagProvider(),
1516
getAngularTagProvider(),
16-
getIonicTagProvider()
17+
getIonicTagProvider(),
18+
getRazorTagProvider()
1719
];
1820

1921
export function doComplete(document: TextDocument, position: Position, doc: HTMLDocument, settings?: CompletionConfiguration): CompletionList {

extensions/razor/OSSREADME.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// ATTENTION - THIS DIRECTORY CONTAINS THIRD PARTY OPEN SOURCE MATERIALS:
2+
[{
3+
"name": "demyte/language-cshtml",
4+
"version": "0.0.0",
5+
"license": "MIT",
6+
"repositoryURL": "https://github.com/demyte/language-cshtml"
7+
}]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"comments": {
3+
"blockComment": [ "<!--", "-->" ]
4+
},
5+
"brackets": [
6+
["<!--", "-->"],
7+
["<", ">"],
8+
["{", "}"],
9+
["(", ")"]
10+
],
11+
"autoClosingPairs": [
12+
{ "open": "{", "close": "}"},
13+
{ "open": "[", "close": "]"},
14+
{ "open": "(", "close": ")" },
15+
{ "open": "'", "close": "'" },
16+
{ "open": "\"", "close": "\"" },
17+
{ "open": "<", "close": ">" }
18+
],
19+
"surroundingPairs": [
20+
{ "open": "'", "close": "'" },
21+
{ "open": "\"", "close": "\"" },
22+
{ "open": "<", "close": ">" }
23+
]
24+
}

extensions/razor/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "razor",
3+
"version": "0.1.0",
4+
"publisher": "vscode",
5+
"engines": {
6+
"vscode": "0.10.x"
7+
},
8+
"scripts": {
9+
"update-grammar": "node ../../build/npm/update-grammar.js demyte/language-cshtml grammars/cshtml.cson ./syntaxes/cshtml.json"
10+
},
11+
"contributes": {
12+
"languages": [{
13+
"id": "razor",
14+
"extensions": [ ".cshtml"],
15+
"aliases": [ "Razor", "razor" ],
16+
"mimetypes": ["text/x-cshtml"]
17+
}],
18+
"grammars": [{
19+
"language": "razor",
20+
"scopeName": "text.html.cshtml",
21+
"path": "./syntaxes/cshtml.json"
22+
}]
23+
}
24+
}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
{
2+
"name": "ASP.NET Razor",
3+
"scopeName": "text.html.cshtml",
4+
"fileTypes": [
5+
"cshtml",
6+
"gohtml"
7+
],
8+
"patterns": [
9+
{
10+
"name": "section.embedded.source.cshtml",
11+
"begin": "(@?([a-zA-Z0-9]+)?)(\\s[a-zA-Z0-9]+)?(\n|\r)?(\\{)",
12+
"beginCaptures": {
13+
"0": {
14+
"name": "punctuation.section.embedded.begin.cshtml"
15+
},
16+
"1": {
17+
"name": "keyword.control.cshtml"
18+
}
19+
},
20+
"patterns": [
21+
{
22+
"name": "section.embedded.source.cshtml",
23+
"begin": "(@?([a-zA-Z0-9]+)?)(\\s[a-zA-Z0-9]+)?(\n|\r)?(\\{)",
24+
"beginCaptures": {
25+
"0": {
26+
"name": "punctuation.section.embedded.begin.cshtml"
27+
},
28+
"1": {
29+
"name": "keyword.control.cshtml"
30+
}
31+
},
32+
"patterns": [
33+
{
34+
"name": "string.quoted.single.cshtml",
35+
"match": "'"
36+
},
37+
{
38+
"include": "#embedded-code"
39+
},
40+
{
41+
"include": "#comments"
42+
},
43+
{
44+
"include": "source.cs"
45+
},
46+
{
47+
"include": "text.html.basic"
48+
}
49+
],
50+
"end": "\\}",
51+
"endCaptures": {
52+
"0": {
53+
"name": "punctuation.section.embedded.begin.cshtml"
54+
}
55+
}
56+
},
57+
{
58+
"name": "string.quoted.single.cshtml",
59+
"match": "'"
60+
},
61+
{
62+
"include": "#embedded-code"
63+
},
64+
{
65+
"include": "#comments"
66+
},
67+
{
68+
"include": "text.html.basic"
69+
}
70+
],
71+
"end": "\\}",
72+
"endCaptures": {
73+
"0": {
74+
"name": "punctuation.section.embedded.begin.cshtml"
75+
}
76+
},
77+
"comments": "Simple multi-line code section"
78+
},
79+
{
80+
"begin": "(@[a-zA-Z0-9]+)(\\s?)",
81+
"captures": {
82+
"0": {
83+
"name": "section.embedded.begin.cshtml"
84+
},
85+
"1": {
86+
"name": "keyword.control.cshtml"
87+
}
88+
},
89+
"patterns": [
90+
{
91+
"match": "(([a-zA-Z0-9]+)(\\.)?)+?",
92+
"captures": {
93+
"2": {
94+
"name": "entity.name.tag.source.cshtml"
95+
},
96+
"3": {
97+
"name": "punctuation.separator.namespace.source.cshtml"
98+
}
99+
}
100+
},
101+
{
102+
"include": "#embedded-code"
103+
},
104+
{
105+
"include": "#comments"
106+
},
107+
{
108+
"include": "source.cs"
109+
},
110+
{
111+
"include": "text.html.basic"
112+
}
113+
],
114+
"end": "(\\n|\\s)",
115+
"comments": "Covers single line Razor tags"
116+
},
117+
{
118+
"include": "#comments"
119+
},
120+
{
121+
"include": "text.html.basic"
122+
}
123+
],
124+
"repository": {
125+
"embedded-code": {
126+
"match": "(@?[a-zA-Z0-9]+)(\\.([a-zA-Z0-9]+))?",
127+
"captures": {
128+
"1": {
129+
"name": "keyword.control.cshtml"
130+
},
131+
"3": {
132+
"name": "entity.name.tag.source.cshtml"
133+
}
134+
},
135+
"patterns": [
136+
{
137+
"include": "#comments"
138+
}
139+
]
140+
},
141+
"comments": {
142+
"begin": "@\\*",
143+
"captures": {
144+
"0": {
145+
"name": "punctuation.definition.comment.source.cshtml"
146+
}
147+
},
148+
"end": "\\*@",
149+
"name": "comment.block.cshtml"
150+
}
151+
},
152+
"version": "https://github.com/demyte/language-cshtml/commit/a49735dc7aef56ae772a3bcfd8e42c89895dcff4"
153+
}

extensions/vscode-colorize-tests/test/colorize-fixtures/test.cshtml renamed to extensions/razor/test/colorize-fixtures/test.cshtml

File renamed without changes.

0 commit comments

Comments
 (0)