wip-6: removed some of the unused parts.
This commit is contained in:
Родитель
e3300c4ed5
Коммит
128ed038c0
|
@ -9,8 +9,4 @@ namespace JetBrains.Annotations {
|
|||
[ThreadSafe]
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Method | AttributeTargets.Struct | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
|
||||
public class ThreadSafeAttribute : Attribute { }
|
||||
|
||||
[ThreadSafe]
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Method | AttributeTargets.Struct | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
|
||||
public class ReadOnlyAttribute : Attribute { }
|
||||
}
|
||||
|
|
|
@ -102,7 +102,6 @@
|
|||
<Compile Include="LanguageIdentifier.cs" />
|
||||
<Compile Include="CoreModule.cs" />
|
||||
<Compile Include="ProcessingOptions.cs" />
|
||||
<Compile Include="ProcessingResultDiagnostic.cs" />
|
||||
<Compile Include="Decompilation\VBNetDecompiler.cs" />
|
||||
<Compile Include="Decompilation\CSharpDecompiler.cs" />
|
||||
<Compile Include="Decompilation\Support\CustomizableIndentPlainTextOutput.cs" />
|
||||
|
@ -113,17 +112,13 @@
|
|||
<Compile Include="Processing\Languages\Internal\VBNetFeatureDiscovery.cs" />
|
||||
<Compile Include="Processing\Languages\VBNetLanguage.cs" />
|
||||
<Compile Include="Processing\Languages\IRoslynLanguage.cs" />
|
||||
<Compile Include="Processing\CodeProcessor.cs" />
|
||||
<Compile Include="Decompilation\Support\DecompiledPseudoCSharpOutputVisitor.cs" />
|
||||
<Compile Include="Decompilation\Support\OverridableCSharpOutputVisitor.cs" />
|
||||
<Compile Include="Decompilation\Support\RoslynFriendlyConvertConstructorCallIntoInitializer.cs" />
|
||||
<Compile Include="Decompilation\AstDecompiler.cs" />
|
||||
<Compile Include="ICodeProcessor.cs" />
|
||||
<Compile Include="Decompilation\IDecompiler.cs" />
|
||||
<Compile Include="ProcessingResult.cs" />
|
||||
<Compile Include="Processing\Languages\CSharpLanguage.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ProcessingResultDiagnosticLocation.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
|
|
|
@ -36,8 +36,6 @@ namespace TryRoslyn.Core {
|
|||
builder.RegisterType<CSharpDecompiler>().As<IDecompiler>().SingleInstance();
|
||||
builder.RegisterType<VBNetDecompiler>().As<IDecompiler>().SingleInstance();
|
||||
builder.RegisterType<ILDecompiler>().As<IDecompiler>().SingleInstance();
|
||||
|
||||
builder.RegisterType<CodeProcessor>().As<ICodeProcessor>().SingleInstance();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
using System;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace TryRoslyn.Core {
|
||||
[ThreadSafe]
|
||||
public interface ICodeProcessor : IDisposable {
|
||||
[NotNull]
|
||||
ProcessingResult Process([NotNull] string code, [CanBeNull] ProcessingOptions options = null);
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using TryRoslyn.Core.Decompilation;
|
||||
using TryRoslyn.Core.Processing.Languages;
|
||||
|
||||
namespace TryRoslyn.Core.Processing {
|
||||
[ThreadSafe]
|
||||
public class CodeProcessor : ICodeProcessor {
|
||||
// ReSharper disable once AgentHeisenbug.FieldOfNonThreadSafeTypeInThreadSafeType
|
||||
private readonly MetadataReference[] _references = {
|
||||
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
|
||||
MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location),
|
||||
MetadataReference.CreateFromFile(typeof(DynamicAttribute).Assembly.Location)
|
||||
};
|
||||
private readonly IReadOnlyCollection<IDecompiler> _decompilers;
|
||||
private readonly IReadOnlyCollection<IRoslynLanguage> _languages;
|
||||
|
||||
public CodeProcessor(
|
||||
IReadOnlyCollection<IRoslynLanguage> languages,
|
||||
IReadOnlyCollection<IDecompiler> decompilers
|
||||
) {
|
||||
_languages = languages;
|
||||
_decompilers = decompilers;
|
||||
}
|
||||
|
||||
public ProcessingResult Process(string code, ProcessingOptions options) {
|
||||
options = options ?? new ProcessingOptions();
|
||||
var kind = options.ScriptMode ? SourceCodeKind.Script : SourceCodeKind.Regular;
|
||||
var sourceLanguage = _languages.Single(l => l.Identifier == options.SourceLanguage);
|
||||
|
||||
var syntaxTree = sourceLanguage.ParseText(code, kind);
|
||||
|
||||
var stream = new MemoryStream();
|
||||
var compilation = sourceLanguage
|
||||
.CreateLibraryCompilation("Test", options.OptimizationsEnabled)
|
||||
.AddReferences(_references)
|
||||
.AddSyntaxTrees(syntaxTree);
|
||||
|
||||
var emitResult = compilation.Emit(stream);
|
||||
|
||||
if (!emitResult.Success)
|
||||
return new ProcessingResult(null, emitResult.Diagnostics.Select(d => new ProcessingResultDiagnostic(d)));
|
||||
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
var resultWriter = new StringWriter();
|
||||
var decompiler = _decompilers.Single(d => d.Language == options.TargetLanguage);
|
||||
decompiler.Decompile(stream, resultWriter);
|
||||
return new ProcessingResult(
|
||||
resultWriter.ToString(),
|
||||
emitResult.Diagnostics.Select(d => new ProcessingResultDiagnostic(d))
|
||||
);
|
||||
}
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
void IDisposable.Dispose() {
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace TryRoslyn.Core {
|
||||
[Serializable]
|
||||
public class ProcessingResult {
|
||||
public string Decompiled { get; private set; }
|
||||
public IReadOnlyList<ProcessingResultDiagnostic> Diagnostics { get; private set; }
|
||||
|
||||
public bool IsSuccess {
|
||||
get { return Decompiled != null; }
|
||||
}
|
||||
|
||||
public ProcessingResult(string decompiled, IEnumerable<ProcessingResultDiagnostic> diagnostics) {
|
||||
Decompiled = decompiled;
|
||||
Diagnostics = diagnostics.ToArray(); // can't use immutables here, as they are non-serializable
|
||||
}
|
||||
|
||||
public IEnumerable<ProcessingResultDiagnostic> GetDiagnostics(DiagnosticSeverity severity) {
|
||||
return Diagnostics.Where(d => d.Severity == severity);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace TryRoslyn.Core {
|
||||
[Serializable]
|
||||
public class ProcessingResultDiagnostic {
|
||||
public ProcessingResultDiagnostic(Diagnostic diagnostic) {
|
||||
Id = diagnostic.Id;
|
||||
Severity = diagnostic.Severity;
|
||||
Message = diagnostic.GetMessage();
|
||||
|
||||
var lineSpan = diagnostic.Location.GetMappedLineSpan();
|
||||
Start = new ProcessingResultDiagnosticLocation(lineSpan.StartLinePosition);
|
||||
End = new ProcessingResultDiagnosticLocation(lineSpan.EndLinePosition);
|
||||
}
|
||||
|
||||
public string Id { get; private set; }
|
||||
public DiagnosticSeverity Severity { get; private set; }
|
||||
public string Message { get; private set; }
|
||||
public ProcessingResultDiagnosticLocation Start { get; private set; }
|
||||
public ProcessingResultDiagnosticLocation End { get; private set; }
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
|
||||
namespace TryRoslyn.Core {
|
||||
[Serializable]
|
||||
public class ProcessingResultDiagnosticLocation {
|
||||
public ProcessingResultDiagnosticLocation(LinePosition position) {
|
||||
Line = position.Line;
|
||||
Column = position.Character;
|
||||
}
|
||||
|
||||
public int Line { get; private set; }
|
||||
public int Column { get; private set; }
|
||||
}
|
||||
}
|
|
@ -12,79 +12,79 @@ using Xunit;
|
|||
|
||||
namespace TryRoslyn.Tests {
|
||||
public class CodeProcessorTests {
|
||||
private static readonly IDictionary<string, LanguageIdentifier> LanguageMap = new Dictionary<string, LanguageIdentifier> {
|
||||
{ "cs", LanguageIdentifier.CSharp },
|
||||
{ "vb", LanguageIdentifier.VBNet },
|
||||
{ "il", LanguageIdentifier.IL }
|
||||
};
|
||||
//private static readonly IDictionary<string, LanguageIdentifier> LanguageMap = new Dictionary<string, LanguageIdentifier> {
|
||||
// { "cs", LanguageIdentifier.CSharp },
|
||||
// { "vb", LanguageIdentifier.VBNet },
|
||||
// { "il", LanguageIdentifier.IL }
|
||||
//};
|
||||
|
||||
[Theory]
|
||||
[InlineData("Constructor.BaseCall.cs2cs")]
|
||||
[InlineData("NullPropagation.ToTernary.cs2cs")]
|
||||
[InlineData("Script.cs2cs")]
|
||||
[InlineData("Simple.cs2il")]
|
||||
[InlineData("Simple.vb2vb")]
|
||||
[InlineData("Module.vb2vb")]
|
||||
public void Process_ReturnsExpectedCode(string resourceName) {
|
||||
var content = GetResourceContent(resourceName);
|
||||
var parts = content.Split("?=>");
|
||||
var code = parts[0].Trim();
|
||||
var expected = parts[1].Trim();
|
||||
//[Theory]
|
||||
//[InlineData("Constructor.BaseCall.cs2cs")]
|
||||
//[InlineData("NullPropagation.ToTernary.cs2cs")]
|
||||
//[InlineData("Script.cs2cs")]
|
||||
//[InlineData("Simple.cs2il")]
|
||||
//[InlineData("Simple.vb2vb")]
|
||||
//[InlineData("Module.vb2vb")]
|
||||
//public void Process_ReturnsExpectedCode(string resourceName) {
|
||||
// var content = GetResourceContent(resourceName);
|
||||
// var parts = content.Split("?=>");
|
||||
// var code = parts[0].Trim();
|
||||
// var expected = parts[1].Trim();
|
||||
|
||||
var result = CreateProcessor().Process(code, GetProcessingOptions(resourceName, content));
|
||||
// var result = CreateProcessor().Process(code, GetProcessingOptions(resourceName, content));
|
||||
|
||||
Assert.True(result.IsSuccess, GetErrorString(result));
|
||||
AssertGold.Equal(expected, result.Decompiled.Trim());
|
||||
}
|
||||
// Assert.True(result.IsSuccess, GetErrorString(result));
|
||||
// AssertGold.Equal(expected, result.Decompiled.Trim());
|
||||
//}
|
||||
|
||||
[Fact]
|
||||
public void Process_CanHandleFormattableString() {
|
||||
var result = CreateProcessor().Process("using System; public class C { public void M() { IFormattable f = $\"{42}\"; } }", new ProcessingOptions {
|
||||
SourceLanguage = LanguageIdentifier.CSharp
|
||||
});
|
||||
//[Fact]
|
||||
//public void Process_CanHandleFormattableString() {
|
||||
// var result = CreateProcessor().Process("using System; public class C { public void M() { IFormattable f = $\"{42}\"; } }", new ProcessingOptions {
|
||||
// SourceLanguage = LanguageIdentifier.CSharp
|
||||
// });
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.True(result.IsSuccess, GetErrorString(result));
|
||||
}
|
||||
// Assert.NotNull(result);
|
||||
// Assert.True(result.IsSuccess, GetErrorString(result));
|
||||
//}
|
||||
|
||||
private static string GetErrorString(ProcessingResult result) {
|
||||
return result.Diagnostics
|
||||
.Aggregate(new StringBuilder("Errors:"), (builder, d) => builder.AppendLine().Append(d))
|
||||
.ToString();
|
||||
}
|
||||
//private static string GetErrorString(ProcessingResult result) {
|
||||
// return result.Diagnostics
|
||||
// .Aggregate(new StringBuilder("Errors:"), (builder, d) => builder.AppendLine().Append(d))
|
||||
// .ToString();
|
||||
//}
|
||||
|
||||
private string GetResourceContent(string name) {
|
||||
var fullName = GetType().Namespace + ".TestCode." + name;
|
||||
// ReSharper disable once AssignNullToNotNullAttribute
|
||||
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(fullName)) {
|
||||
if (stream == null)
|
||||
throw new FileNotFoundException("Resource was not found.", fullName);
|
||||
//private string GetResourceContent(string name) {
|
||||
// var fullName = GetType().Namespace + ".TestCode." + name;
|
||||
// // ReSharper disable once AssignNullToNotNullAttribute
|
||||
// using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(fullName)) {
|
||||
// if (stream == null)
|
||||
// throw new FileNotFoundException("Resource was not found.", fullName);
|
||||
|
||||
using (var reader = new StreamReader(stream)) {
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
// using (var reader = new StreamReader(stream)) {
|
||||
// return reader.ReadToEnd();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
private ProcessingOptions GetProcessingOptions(string resourceName, string content) {
|
||||
var scriptMode = content.StartsWith("// script mode") || content.StartsWith("' Script Mode");
|
||||
var fromTo = Path.GetExtension(resourceName).TrimStart('.').Split('2');
|
||||
//private ProcessingOptions GetProcessingOptions(string resourceName, string content) {
|
||||
// var scriptMode = content.StartsWith("// script mode") || content.StartsWith("' Script Mode");
|
||||
// var fromTo = Path.GetExtension(resourceName).TrimStart('.').Split('2');
|
||||
|
||||
return new ProcessingOptions {
|
||||
SourceLanguage = LanguageMap[fromTo[0]],
|
||||
TargetLanguage = LanguageMap[fromTo[1]],
|
||||
OptimizationsEnabled = true,
|
||||
ScriptMode = scriptMode
|
||||
};
|
||||
}
|
||||
// return new ProcessingOptions {
|
||||
// SourceLanguage = LanguageMap[fromTo[0]],
|
||||
// TargetLanguage = LanguageMap[fromTo[1]],
|
||||
// OptimizationsEnabled = true,
|
||||
// ScriptMode = scriptMode
|
||||
// };
|
||||
//}
|
||||
|
||||
private static CodeProcessor CreateProcessor() {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterModule<CoreModule>();
|
||||
builder.RegisterType<CodeProcessor>().AsSelf();
|
||||
var container = builder.Build();
|
||||
//private static CodeProcessor CreateProcessor() {
|
||||
// var builder = new ContainerBuilder();
|
||||
// builder.RegisterModule<CoreModule>();
|
||||
// builder.RegisterType<CodeProcessor>().AsSelf();
|
||||
// var container = builder.Build();
|
||||
|
||||
return container.Resolve<CodeProcessor>();
|
||||
}
|
||||
// return container.Resolve<CodeProcessor>();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=Html_002ETagNotResolved/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InconsistentNaming/@EntryIndexedValue">HINT</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/JsInspections/LanguageLevel/@EntryValue">Experimental</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ACCESSOR_DECLARATION_BRACES/@EntryValue">END_OF_LINE</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ACCESSOR_OWNER_DECLARATION_BRACES/@EntryValue">END_OF_LINE</s:String>
|
||||
|
|
|
@ -8,7 +8,7 @@ using MirrorSharp;
|
|||
using MirrorSharp.Advanced;
|
||||
using MirrorSharp.Owin;
|
||||
using Owin;
|
||||
using TryRoslyn.Core;
|
||||
using TryRoslyn.Core.Decompilation;
|
||||
using TryRoslyn.Web.Api;
|
||||
|
||||
[assembly: OwinStartup(typeof(Startup), nameof(Startup.Configuration))]
|
||||
|
@ -38,8 +38,8 @@ namespace TryRoslyn.Web.Api {
|
|||
private static IContainer CreateContainer() {
|
||||
var builder = new ContainerBuilder();
|
||||
var apiAssembly = Assembly.GetExecutingAssembly();
|
||||
|
||||
builder.RegisterAssemblyModules(typeof(ICodeProcessor).Assembly);
|
||||
|
||||
builder.RegisterAssemblyModules(typeof(IDecompiler).Assembly);
|
||||
builder.RegisterAssemblyModules(apiAssembly);
|
||||
|
||||
return builder.Build();
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
|
|
@ -181,8 +181,11 @@
|
|||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="js\ui\components\app-codemirror.js" />
|
||||
<Content Include="js\ui\components\app-favicon-replace-href.js" />
|
||||
<Content Include="js\ui\components\app-loader.js" />
|
||||
<Content Include="js\ui\components\app-mirrorsharp-diagnostic.js" />
|
||||
<Content Include="js\ui\components\app-mirrorsharp.js" />
|
||||
<Content Include="webpack.config.js" />
|
||||
<Content Include=".brackets.json" />
|
||||
<None Include="legacy\directives\syntaxtree.js" />
|
||||
|
@ -191,13 +194,10 @@
|
|||
<Content Include="index.html" />
|
||||
<Content Include="js\app.js" />
|
||||
<Content Include="js\server\get-branches-async.js" />
|
||||
<Content Include="js\server\send-code-async.js" />
|
||||
<Content Include="js\state\handlers\defaults.js" />
|
||||
<Content Include="js\state\handlers\last-used.js" />
|
||||
<Content Include="js\state\handlers\url.js" />
|
||||
<Content Include="js\state\index.js" />
|
||||
<Content Include="js\ui\components\app-codemirror.js" />
|
||||
<Content Include="js\ui\components\app-diagnostic.js" />
|
||||
<Content Include="js\ui\components\app-mobile-shelf.js" />
|
||||
<Content Include="js\ui\filters\app-date.js" />
|
||||
<Content Include="js\ui\filters\app-trim.js" />
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<!DOCTYPE html>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
|
@ -131,7 +131,7 @@
|
|||
<app-loader></app-loader>
|
||||
<ul>
|
||||
<li v-for="error in result.errors">
|
||||
<app-mirrorsharp-diagnostic v-bind:model="error" severity="error"></app-diagnostic>
|
||||
<app-mirrorsharp-diagnostic v-bind:model="error" severity="error"></app-mirrorsharp-diagnostic>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -144,7 +144,7 @@
|
|||
<div class="content">
|
||||
<ul>
|
||||
<li v-for="warning in result.warnings">
|
||||
<app-mirrorsharp-diagnostic v-bind:model="warning" severity="warning"></app-diagnostic>
|
||||
<app-mirrorsharp-diagnostic v-bind:model="warning" severity="warning"></app-mirrorsharp-diagnostic>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import CodeMirror from 'codemirror';
|
||||
|
||||
import getBranchesAsync from './server/get-branches-async';
|
||||
|
||||
import state from './state';
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
import $ from 'jquery';
|
||||
|
||||
export default function sendCodeAsync(code, options, branchUrl) {
|
||||
let url = 'api/compilation';
|
||||
if (branchUrl)
|
||||
url = branchUrl.replace(/\/?$/, '/') + url;
|
||||
|
||||
const data = Object.assign({ code: code }, options);
|
||||
const xhr = $.ajax({
|
||||
type: 'POST',
|
||||
url: url,
|
||||
datatype: 'application/json',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(data)
|
||||
});
|
||||
const promise = xhr.then(
|
||||
data => data,
|
||||
response => {
|
||||
let error;
|
||||
if (response.statusText === 'abort') {
|
||||
error = Error('Request aborted.');
|
||||
error.reason = 'abort';
|
||||
return error;
|
||||
}
|
||||
|
||||
error = Error('Request failed.');
|
||||
error.reason = 'response';
|
||||
error.response = {
|
||||
data: JSON.parse(response.responseText)
|
||||
};
|
||||
return error;
|
||||
}
|
||||
);
|
||||
promise.abort = () => xhr.abort();
|
||||
return promise;
|
||||
}
|
|
@ -1,20 +1,12 @@
|
|||
import Vue from 'vue';
|
||||
import CodeMirror from 'codemirror';
|
||||
import 'codemirror/addon/lint/lint';
|
||||
import 'codemirror/mode/clike/clike';
|
||||
import 'codemirror/mode/vb/vb';
|
||||
|
||||
function buildGetAnnotations(data) {
|
||||
return (cm, updateLinting) => {
|
||||
data.lint(data.value, updateLinting);
|
||||
};
|
||||
}
|
||||
|
||||
Vue.component('app-codemirror', {
|
||||
props: {
|
||||
value: String,
|
||||
mode: String,
|
||||
lint: Function,
|
||||
options: Object
|
||||
},
|
||||
ready: function() {
|
||||
|
@ -23,10 +15,7 @@ Vue.component('app-codemirror', {
|
|||
const options = Object.assign(
|
||||
{},
|
||||
this.options,
|
||||
this.mode !== undefined ? { mode: this.mode } : {},
|
||||
this.lint !== undefined ? {
|
||||
lint: { async: true, getAnnotations: buildGetAnnotations(this) }
|
||||
} : {}
|
||||
this.mode !== undefined ? { mode: this.mode } : {}
|
||||
);
|
||||
const instance = CodeMirror.fromTextArea(textarea, options);
|
||||
this.$watch('mode', value => instance.setOption('mode', value));
|
||||
|
|
Загрузка…
Ссылка в новой задаче