Improved the Go support, added Go editor to the Explorer project (but not used yet).
This commit is contained in:
Родитель
c707afd773
Коммит
ddba4c1c05
|
@ -6,8 +6,14 @@ import (
|
|||
"go/importer"
|
||||
"go/token"
|
||||
"go/types"
|
||||
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"encoding/base64"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/beevik/etree"
|
||||
)
|
||||
|
||||
|
@ -100,7 +106,8 @@ func Walk(parent *etree.Element, node ast.Node, fileset *token.FileSet, info *ty
|
|||
addPositionStartEnd(identNode, n.Pos(), n.End(), fileset)
|
||||
|
||||
case *ast.BadExpr:
|
||||
// nothing to do
|
||||
badExprNode := parent.CreateElement("BadExpression")
|
||||
addPositionStartEnd(badExprNode, n.Pos(), n.End(), fileset)
|
||||
|
||||
case *ast.BasicLit:
|
||||
var literalNode *etree.Element
|
||||
|
@ -367,7 +374,8 @@ func Walk(parent *etree.Element, node ast.Node, fileset *token.FileSet, info *ty
|
|||
|
||||
// Statements
|
||||
case *ast.BadStmt:
|
||||
// TODO: nothing to do?
|
||||
badStatementNode := parent.CreateElement("BadStatement")
|
||||
addPositionStartEnd(badStatementNode, n.Pos(), n.End(), fileset)
|
||||
|
||||
// https://golang.org/pkg/go/ast/#DeclStmt
|
||||
// A DeclStmt node represents a declaration in a statement list.
|
||||
|
@ -622,7 +630,8 @@ func Walk(parent *etree.Element, node ast.Node, fileset *token.FileSet, info *ty
|
|||
addPositionStartEnd(itemNode, n.Pos(), n.End(), fileset)
|
||||
|
||||
case *ast.BadDecl:
|
||||
// TODO: nothing to do?
|
||||
badDeclNode := parent.CreateElement("BadDeclaration")
|
||||
addPositionStartEnd(badDeclNode, n.Pos(), n.End(), fileset)
|
||||
|
||||
case *ast.GenDecl:
|
||||
var declkind string = ""
|
||||
|
@ -669,6 +678,23 @@ func Walk(parent *etree.Element, node ast.Node, fileset *token.FileSet, info *ty
|
|||
fileNode.CreateAttr("Package", n.Name.Name)
|
||||
fileNode.CreateAttr("Filename", fileset.File(n.Package).Name())
|
||||
|
||||
file, err := os.Open(fileset.File(n.Package).Name())
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
source, err := ioutil.ReadAll(file)
|
||||
// Encode the file in Base64, since this XML implementation does not
|
||||
// quote illegal characters (like <, > etc.).
|
||||
encoded := base64.StdEncoding.EncodeToString([]byte(source))
|
||||
fileNode.CreateAttr("Source", encoded)
|
||||
|
||||
defer func() {
|
||||
if err = file.Close(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
if n.Doc != nil {
|
||||
Walk(fileNode, n.Doc, fileset, info)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
<SyntaxDefinition name="Go" extensions=".go" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
|
||||
<RuleSet ignoreCase="false">
|
||||
<Keywords foreground="blue" fontWeight="bold">
|
||||
<Word>break</Word>
|
||||
<Word>case</Word>
|
||||
<Word>chan</Word>
|
||||
<Word>const</Word>
|
||||
<Word>continue</Word>
|
||||
<Word>default</Word>
|
||||
<Word>defer</Word>
|
||||
<Word>delete</Word>
|
||||
<Word>else</Word>
|
||||
<Word>fallthrough</Word>
|
||||
<Word>false</Word>
|
||||
<Word>for</Word>
|
||||
<Word>func</Word>
|
||||
<Word>go</Word>
|
||||
<Word>goto</Word>
|
||||
<Word>if</Word>
|
||||
<Word>import</Word>
|
||||
<Word>interface</Word>
|
||||
<Word>iota</Word>
|
||||
<Word>map</Word>
|
||||
<Word>nil</Word>
|
||||
<Word>package</Word>
|
||||
<Word>range</Word>
|
||||
<Word>return</Word>
|
||||
<Word>select</Word>
|
||||
<Word>struct</Word>
|
||||
<Word>switch</Word>
|
||||
<Word>true</Word>
|
||||
<Word>type</Word>
|
||||
<Word>var</Word>
|
||||
</Keywords>
|
||||
<Keywords foreground="#FF804040" fontWeight="normal">
|
||||
<Word>append</Word>
|
||||
<Word>cap</Word>
|
||||
<Word>close</Word>
|
||||
<Word>closed</Word>
|
||||
<Word>copy</Word>
|
||||
<Word>imag</Word>
|
||||
<Word>len</Word>
|
||||
<Word>main</Word>
|
||||
<Word>make</Word>
|
||||
<Word>new</Word>
|
||||
<Word>panic</Word>
|
||||
<Word>print</Word>
|
||||
<Word>println</Word>
|
||||
<Word>real</Word>
|
||||
<Word>recover</Word>
|
||||
</Keywords>
|
||||
<Keywords foreground="#FF008080" fontWeight="normal">
|
||||
<Word>bool</Word>
|
||||
<Word>byte</Word>
|
||||
<Word>complex</Word>
|
||||
<Word>complex128</Word>
|
||||
<Word>complex64</Word>
|
||||
<Word>error</Word>
|
||||
<Word>float</Word>
|
||||
<Word>float32</Word>
|
||||
<Word>float64</Word>
|
||||
<Word>int</Word>
|
||||
<Word>int16</Word>
|
||||
<Word>int32</Word>
|
||||
<Word>int64</Word>
|
||||
<Word>int8</Word>
|
||||
<Word>rune</Word>
|
||||
<Word>string</Word>
|
||||
<Word>uint</Word>
|
||||
<Word>uint16</Word>
|
||||
<Word>uint32</Word>
|
||||
<Word>uint64</Word>
|
||||
<Word>uint8</Word>
|
||||
<Word>uintptr</Word>
|
||||
</Keywords>
|
||||
<Span foreground="#FF008000" fontWeight="normal" fontStyle="normal">
|
||||
<Begin>//</Begin>
|
||||
</Span>
|
||||
<Span foreground="#FFFFC0CB" fontWeight="normal" fontStyle="normal" multiline="true">
|
||||
<Begin>/\*</Begin>
|
||||
<End>\*/</End>
|
||||
</Span>
|
||||
<Span foreground="#FF800000" fontWeight="normal" fontStyle="normal" multiline="true">
|
||||
<Begin>"</Begin>
|
||||
<End>"</End>
|
||||
<RuleSet>
|
||||
<Span begin="\\" end="." />
|
||||
</RuleSet>
|
||||
</Span>
|
||||
<Span foreground="#FF800000" fontWeight="normal" fontStyle="normal">
|
||||
<Begin>'</Begin>
|
||||
<End>'</End>
|
||||
</Span>
|
||||
<Rule foreground="#FFA0911F">\b0[xX][0-9a-fA-F]+|(\b\d+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?</Rule>
|
||||
</RuleSet>
|
||||
</SyntaxDefinition>
|
|
@ -22,6 +22,7 @@
|
|||
<None Remove="Images\Alecive-Flatwoken-Apps-File-Xml.ico" />
|
||||
<None Remove="Images\Alecive-Flatwoken-Apps-File-Xml.ico" />
|
||||
<None Remove="Images\High Contrast Socrates.png" />
|
||||
<None Remove="Resources\Go.xshd" />
|
||||
<None Include="..\LICENSE.txt">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
|
@ -73,6 +74,7 @@
|
|||
<Resource Include="Images\Colorful spinning wheel.gif" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\Go.xshd" />
|
||||
<EmbeddedResource Include="Resources\XQuery.xshd" />
|
||||
<EmbeddedResource Include="Resources\CSharp-Mode.xshd" />
|
||||
<EmbeddedResource Include="Resources\Java-Mode.xshd" />
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace XppReasoningWpf
|
||||
{
|
||||
using System.Windows.Data;
|
||||
|
||||
class GoSourceEditor : SourceEditor
|
||||
{
|
||||
public GoSourceEditor()
|
||||
{
|
||||
var fontFamilyBinding = new Binding("SourceFont");
|
||||
fontFamilyBinding.Source = Properties.Settings.Default;
|
||||
this.SetBinding(FontFamilyProperty, fontFamilyBinding);
|
||||
|
||||
this.SyntaxHighlighting = this.LoadHighlightDefinition("Go.xshd");
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче