Skip to content

Commit

Permalink
Merge pull request #50 from mghdotdev/feature/mvt-in-js-css
Browse files Browse the repository at this point in the history
Feature/mvt in js css
  • Loading branch information
mghdotdev authored Apr 12, 2023
2 parents a2e97a1 + acab858 commit 5a2323a
Show file tree
Hide file tree
Showing 20 changed files with 448 additions and 75 deletions.
9 changes: 9 additions & 0 deletions .hintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": [
"development"
],
"hints": {
"typescript-config/strict": "off",
"typescript-config/consistent-casing": "off"
}
}
2 changes: 0 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"name": "Launch Client",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}" ],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/client/out/**/*.js"],
"preLaunchTask": "npm: watch"
Expand All @@ -17,7 +16,6 @@
"request": "attach",
"name": "Attach to Server",
"address": "localhost",
"protocol": "inspector",
"port": 6045,
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/server/out/**/*.js"]
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Max Hegler
Copyright (c) 2023 Max Hegler

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 6 additions & 2 deletions client/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export function activate( context: ExtensionContext ) {
let documentSelector = [
{ scheme: 'file', language: 'mvt' },
{ scheme: 'untitled', language: 'mvt' },
{ scheme: 'file', language: 'mvtcss' },
{ scheme: 'untitled', language: 'mvtcss' },
{ scheme: 'file', language: 'mvtjs' },
{ scheme: 'untitled', language: 'mvtjs' },
{ scheme: 'file', language: 'mv' },
{ scheme: 'untitled', language: 'mv' }
];
Expand All @@ -53,7 +57,7 @@ export function activate( context: ExtensionContext ) {
client.registerProposedFeatures();
let clientDisposable = client.start();

// push client to context
// push client to context
context.subscriptions.push( clientDisposable );

// set advanced language configurations
Expand Down Expand Up @@ -93,7 +97,7 @@ export function activate( context: ExtensionContext ) {
}
],
});

// push all commands to context
pushAll( context.subscriptions, mivaCommands );

Expand Down
28 changes: 16 additions & 12 deletions client/src/mivaCommands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import patterns from './util/patterns';
import { TextEditor, TextEditorEdit, Range, commands, env, window, workspace, Uri, languages, Position } from 'vscode';
import { TextEditor, TextEditorEdit, Range, commands, env, window, workspace, Uri, languages, Position, CharacterPair } from 'vscode';

const boundryAmount = 200;

Expand Down Expand Up @@ -39,13 +39,13 @@ const insertFileNameCommand = commands.registerTextEditorCommand( 'mivaIde.inser
if ( leftMatch ) {

insertEdit( leftMatch[0].length, ` ${ fileName } ` );

}

}

leftMatch = patterns.SHARED.LEFT_FILE_ATTR.exec( left );

// define helper method for inserting file name
function insertEdit( matchLength: number, fileName: string ) {

Expand All @@ -58,7 +58,7 @@ const insertFileNameCommand = commands.registerTextEditorCommand( 'mivaIde.inser

// check & execute the insertion
if ( leftMatch ) {

insertEdit( leftMatch[0].length, fileName );

}
Expand Down Expand Up @@ -131,7 +131,7 @@ function convertVariableToEntity( variable: string, uri?: Uri ) {
const convertAndCopyCommand = commands.registerTextEditorCommand( 'mivaIde.MVT.convertAndCopy', ( textEditor: TextEditor ) => {

// exit if not MVT
if ( textEditor.document.languageId !== 'mvt' ) {
if ( textEditor.document.languageId !== 'mvt' && textEditor.document.languageId !== 'mvtcss' && textEditor.document.languageId !== 'mvtjs' ) {
return;
}

Expand Down Expand Up @@ -162,7 +162,7 @@ const convertAndCopyCommand = commands.registerTextEditorCommand( 'mivaIde.MVT.c
const convertToEntityCommand = commands.registerTextEditorCommand( 'mivaIde.MVT.convertToEntity', ( textEditor: TextEditor, edit: TextEditorEdit ) => {

// exit if not MVT
if ( textEditor.document.languageId !== 'mvt' ) {
if ( textEditor.document.languageId !== 'mvt' && textEditor.document.languageId !== 'mvtcss' && textEditor.document.languageId !== 'mvtjs' ) {
return;
}

Expand All @@ -186,7 +186,7 @@ const convertToEntityCommand = commands.registerTextEditorCommand( 'mivaIde.MVT.
const convertToVariableCommand = commands.registerTextEditorCommand( 'mivaIde.MVT.convertToVariable', ( textEditor: TextEditor, edit: TextEditorEdit ) => {

// exit if not MVT
if ( textEditor.document.languageId !== 'mvt' ) {
if ( textEditor.document.languageId !== 'mvt' && textEditor.document.languageId !== 'mvtcss' && textEditor.document.languageId !== 'mvtjs' ) {
return;
}

Expand All @@ -211,15 +211,19 @@ const insertHtmlComment = commands.registerTextEditorCommand( 'mivaIde.toggleHtm

const languageId = textEditor.document.languageId;

if ( languageId === 'mvt' || languageId === 'mv' ) {

languages.setLanguageConfiguration( languageId, { comments: { blockComment: [ '<!--', '-->' ] } } );
if ( languageId === 'mvt' || languageId === 'mvtcss' || languageId === 'mvtjs' || languageId === 'mv' ) {

const blockComment: CharacterPair = languageId === 'mvtcss' || languageId === 'mvtjs'
? [ '/*', '*/' ]
: [ '<!--', '-->' ];

languages.setLanguageConfiguration( languageId, { comments: { blockComment: blockComment } } );

commands.executeCommand( 'editor.action.blockComment' ).then(() => {

languages.setLanguageConfiguration( languageId, { comments: { blockComment: ( languageId == 'mv' ) ? [ '<MvCOMMENT>', '</MvCOMMENT>' ] : [ '<mvt:comment>', '</mvt:comment>' ] } } );

});
});

}
else {
Expand All @@ -232,7 +236,7 @@ const insertHtmlComment = commands.registerTextEditorCommand( 'mivaIde.toggleHtm

const calculatePosNumberCommand = commands.registerTextEditorCommand( 'mivaIde.MVT.calculatePosNumber', ( textEditor: TextEditor, edit: TextEditorEdit ) => {

if ( textEditor.document.languageId !== 'mvt' ) {
if ( textEditor.document.languageId !== 'mvt' && textEditor.document.languageId !== 'mvtcss' && textEditor.document.languageId !== 'mvtjs' ) {
return;
}

Expand Down
39 changes: 39 additions & 0 deletions configurations/MVT/mvtcss.configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"comments": {
"blockComment": [ "<mvt:comment>", "</mvt:comment>" ]
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"],
[ "<", ">" ],
[ "<mvt:comment>", "</mvt:comment>" ]
],
"autoClosingPairs": [
{ "open": "{", "close": "}", "notIn": ["string", "comment"] },
{ "open": "[", "close": "]", "notIn": ["string", "comment"] },
{ "open": "(", "close": ")", "notIn": ["string", "comment"] },
{ "open": "\"", "close": "\"", "notIn": ["string", "comment"] },
{ "open": "'", "close": "'", "notIn": ["string", "comment"] },
{ "open": "<mvt:comment>", "close": "</mvt:comment>", "notIn": [ "comment", "string" ] }
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"],
{ "open": "<", "close": ">" }
],
"folding": {
"markers": {
"start": "^\\s*\\/\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\/",
"end": "^\\s*\\/\\*\\s*#endregion\\b.*\\*\\/"
}
},
"indentationRules": {
"increaseIndentPattern": "(^.*\\{[^}]*$)",
"decreaseIndentPattern": "^\\s*\\}"
},
"wordPattern": "(#?-?\\d*\\.\\d\\w*%?)|(::?[\\w-]*(?=[^,{;]*[,{]))|(([@#.!])?[\\w-?]+%?|[@#!.])"
}
196 changes: 196 additions & 0 deletions configurations/MVT/mvtjs.configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
{
// Note that this file should stay in sync with 'typescript-language-basics/language-configuration.json'
"comments": {
"lineComment": "//",
"blockComment": [
"<mvt:comment>",
"</mvt:comment>"
]
},
"brackets": [
[
"${",
"}"
],
[
"{",
"}"
],
[
"[",
"]"
],
[
"(",
")"
],
[ "<", ">" ],
[ "<mvt:comment>", "</mvt:comment>" ]
],
"autoClosingPairs": [
{
"open": "{",
"close": "}"
},
{
"open": "[",
"close": "]"
},
{
"open": "(",
"close": ")"
},
{
"open": "'",
"close": "'",
"notIn": [
"string",
"comment"
]
},
{
"open": "\"",
"close": "\"",
"notIn": [
"string"
]
},
{
"open": "`",
"close": "`",
"notIn": [
"string",
"comment"
]
},
{
"open": "/**",
"close": " */",
"notIn": [
"string"
]
},
{ "open": "<mvt:comment>", "close": "</mvt:comment>", "notIn": [ "comment", "string" ] }
],
"surroundingPairs": [
[
"{",
"}"
],
[
"[",
"]"
],
[
"(",
")"
],
[
"'",
"'"
],
[
"\"",
"\""
],
[
"`",
"`"
],
[
"<",
">"
]
],
"autoCloseBefore": ";:.,=}])>` \n\t",
"folding": {
"markers": {
"start": "^\\s*//\\s*#?region\\b",
"end": "^\\s*//\\s*#?endregion\\b"
}
},
"wordPattern": {
"pattern": "(-?\\d*\\.\\d\\w*)|([^\\`\\~\\@\\!\\%\\^\\&\\*\\(\\)\\-\\=\\+\\[\\{\\]\\}\\\\\\|\\;\\:\\'\\\"\\,\\.\\<\\>/\\?\\s]+)",
},
"indentationRules": {
"decreaseIndentPattern": {
"pattern": "^((?!.*?/\\*).*\\*\/)?\\s*[\\}\\]].*$"
},
"increaseIndentPattern": {
"pattern": "^((?!//).)*(\\{([^}\"'`/]*|(\\t|[ ])*//.*)|\\([^)\"'`/]*|\\[[^\\]\"'`/]*)$"
},
// e.g. * ...| or */| or *-----*/|
"unIndentedLinePattern": {
"pattern": "^(\\t|[ ])*[ ]\\*[^/]*\\*/\\s*$|^(\\t|[ ])*[ ]\\*/\\s*$|^(\\t|[ ])*[ ]\\*([ ]([^\\*]|\\*(?!/))*)?$"
}
},
"onEnterRules": [
{
// e.g. /** | */
"beforeText": {
"pattern": "^\\s*/\\*\\*(?!/)([^\\*]|\\*(?!/))*$"
},
"afterText": {
"pattern": "^\\s*\\*/$"
},
"action": {
"indent": "indentOutdent",
"appendText": " * "
}
},
{
// e.g. /** ...|
"beforeText": {
"pattern": "^\\s*/\\*\\*(?!/)([^\\*]|\\*(?!/))*$"
},
"action": {
"indent": "none",
"appendText": " * "
}
},
{
// e.g. * ...|
"beforeText": {
"pattern": "^(\\t|[ ])*[ ]\\*([ ]([^\\*]|\\*(?!/))*)?$"
},
"previousLineText": {
"pattern": "(?=^(\\s*(/\\*\\*|\\*)).*)(?=(?!(\\s*\\*/)))"
},
"action": {
"indent": "none",
"appendText": "* "
}
},
{
// e.g. */|
"beforeText": {
"pattern": "^(\\t|[ ])*[ ]\\*/\\s*$"
},
"action": {
"indent": "none",
"removeText": 1
},
},
{
// e.g. *-----*/|
"beforeText": {
"pattern": "^(\\t|[ ])*[ ]\\*[^/]*\\*/\\s*$"
},
"action": {
"indent": "none",
"removeText": 1
},
},
{
"beforeText": {
"pattern": "^\\s*(\\bcase\\s.+:|\\bdefault:)$"
},
"afterText": {
"pattern": "^(?!\\s*(\\bcase\\b|\\bdefault\\b))"
},
"action": {
"indent": "indent"
}
}
]
}
Loading

0 comments on commit 5a2323a

Please sign in to comment.