XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension.NetCore.VSIX

【VSIX】XFEExtension的Visual Studio扩展

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFEExtension.NetCore.VSIX

完善代码片段

6a64428
XFE工作室室长 <xfe18827675401@126.com>
提交于

代码差异

11 个文件 +20 -289
Deleted XFEExtension.NetCore.VSIX/SnippetUtilities.cs +0 -7
@@ -1,7 +0,0 @@
1 namespace XFEExtension.NetCore.VSIX
2 {
3 static class SnippetUtilities
4 {
5 internal const string LanguageServiceGuidStr = "26e90afd-9260-4229-819a-61538e0198f7";
6 }
7 }
Renamed XFEExtension.NetCore.VSIX/XFEExtension CodeSnippets/XFEExtension CSharp/cr.snippet +2 -2
@@ -1,5 +1,5 @@
1 1 <?xml version="1.0" encoding="utf-8"?>
2 <XFEExtensionSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
2 <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
3 3 <CodeSnippet Format="1.0.0">
4 4 <Header>
5 5 <Title>cr</Title>
@@ -21,4 +21,4 @@
21 21 </Code>
22 22 </Snippet>
23 23 </CodeSnippet>
24 </XFEExtensionSnippets>
24 </CodeSnippets>
Renamed XFEExtension.NetCore.VSIX/XFEExtension CodeSnippets/XFEExtension CSharp/to.snippet +2 -2
@@ -1,5 +1,5 @@
1 1 <?xml version="1.0" encoding="utf-8"?>
2 <XFEExtensionSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
2 <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
3 3 <CodeSnippet Format="1.0.0">
4 4 <Header>
5 5 <Title>to</Title>
@@ -21,4 +21,4 @@
21 21 </Code>
22 22 </Snippet>
23 23 </CodeSnippet>
24 </XFEExtensionSnippets>
24 </CodeSnippets>
Added XFEExtension.NetCore.VSIX/XFEExtension CodeSnippets/XFEExtensionCodeSnippets.pkgdef +2 -0
@@ -0,0 +1,2 @@
1 [$RootKey$\Languages\CodeExpansions\CSharp\Paths]
2 "XFEExtension CSharp"="$PackageFolder$"
Modified XFEExtension.NetCore.VSIX/XFEExtension.NetCore.VSIX.csproj +7 -8
@@ -46,20 +46,19 @@
46 46 </PropertyGroup>
47 47 <ItemGroup>
48 48 <Compile Include="Properties\AssemblyInfo.cs" />
49 <Compile Include="SnippetUtilities.cs" />
50 49 <Compile Include="XFEExtension.NetCore.VSIXPackage.cs" />
51 <Compile Include="XFEExtensionCompletionCommandHandler.cs" />
52 <Compile Include="XFEExtensionCompletionHandlerProvider.cs" />
53 <Compile Include="XFEExtensionCompletionSource.cs" />
54 <Compile Include="XFEExtensionCompletionSourceProvider.cs" />
55 50 </ItemGroup>
56 51 <ItemGroup>
57 <Content Include="XFEExtensionSnippets\XFESnippets.xml" />
58 <Content Include="XFEExtensionSnippets\CodeSnippets\cr.snippet">
52 <Content Include="XFEExtension CodeSnippets\XFEExtension CSharp\cr.snippet">
59 53 <CopyToOutputDirectory>Always</CopyToOutputDirectory>
60 54 <IncludeInVSIX>true</IncludeInVSIX>
61 55 </Content>
62 <Content Include="XFEExtensionSnippets\CodeSnippets\to.snippet">
56 <Content Include="XFEExtension CodeSnippets\XFEExtension CSharp\to.snippet">
57 <IncludeInVSIX>true</IncludeInVSIX>
58 <CopyToOutputDirectory>Always</CopyToOutputDirectory>
59 </Content>
60 <Content Include="XFEExtension CodeSnippets\XFEExtensionCodeSnippets.pkgdef">
61 <CopyToOutputDirectory>Always</CopyToOutputDirectory>
63 62 <IncludeInVSIX>true</IncludeInVSIX>
64 63 </Content>
65 64 <None Include="source.extension.vsixmanifest">
Deleted XFEExtension.NetCore.VSIX/XFEExtensionCompletionCommandHandler.cs +0 -146
@@ -1,146 +0,0 @@
1 using Microsoft.VisualStudio;
2 using Microsoft.VisualStudio.Language.Intellisense;
3 using Microsoft.VisualStudio.OLE.Interop;
4 using Microsoft.VisualStudio.Shell;
5 using Microsoft.VisualStudio.Text;
6 using Microsoft.VisualStudio.Text.Editor;
7 using Microsoft.VisualStudio.TextManager.Interop;
8 using System;
9 using System.Runtime.InteropServices;
10
11 namespace XFEExtension.NetCore.VSIX
12 {
13 [ProvideLanguageCodeExpansion(
14 SnippetUtilities.LanguageServiceGuidStr,
15 "XFEExtensionSnippets", //the language name
16 0, //the resource id of the language
17 "XFEExtensionSnippets", //the language ID used in the .snippet files
18 @"%InstallRoot%\XFEExtensionSnippets\XFEExtensionSnippets.xml",
19 //the path of the index file
20 SearchPaths = @"%InstallRoot%\XFEExtensionSnippets\CodeSnippets\",
21 ForceCreateDirs = @"%InstallRoot%\XFEExtensionSnippets\CodeSnippets\")]
22 internal class XFEExtensionCompletionCommandHandler: IOleCommandTarget
23 {
24 private IOleCommandTarget m_nextCommandHandler;
25 private ITextView m_textView;
26 private XFEExtensionCompletionHandlerProvider m_provider;
27 private ICompletionSession m_session;
28 internal XFEExtensionCompletionCommandHandler(IVsTextView textViewAdapter, ITextView textView, XFEExtensionCompletionHandlerProvider provider)
29 {
30 this.m_textView = textView;
31 this.m_provider = provider;
32
33 //add the command to the command chain
34 textViewAdapter.AddCommandFilter(this, out m_nextCommandHandler);
35 }
36 public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
37 {
38 if (!VsShellUtilities.IsInAutomationFunction(m_provider.ServiceProvider))
39 {
40 if (pguidCmdGroup == VSConstants.VSStd2K && cCmds > 0)
41 {
42 // make the Insert Snippet command appear on the context menu
43 if ((uint)prgCmds[0].cmdID == (uint)VSConstants.VSStd2KCmdID.INSERTSNIPPET)
44 {
45 prgCmds[0].cmdf = (int)Constants.MSOCMDF_ENABLED | (int)Constants.MSOCMDF_SUPPORTED;
46 return VSConstants.S_OK;
47 }
48 }
49 }
50
51 return m_nextCommandHandler.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);
52 }
53
54 public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
55 {
56 if (VsShellUtilities.IsInAutomationFunction(m_provider.ServiceProvider))
57 {
58 return m_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
59 }
60 //make a copy of this so we can look at it after forwarding some commands
61 uint commandID = nCmdID;
62 char typedChar = char.MinValue;
63 //make sure the input is a char before getting it
64 if (pguidCmdGroup == VSConstants.VSStd2K && nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR)
65 {
66 typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
67 }
68
69 //check for a commit character
70 if (nCmdID == (uint)VSConstants.VSStd2KCmdID.RETURN
71 || nCmdID == (uint)VSConstants.VSStd2KCmdID.TAB
72 || (char.IsWhiteSpace(typedChar) || char.IsPunctuation(typedChar)))
73 {
74 //check for a selection
75 if (m_session != null && !m_session.IsDismissed)
76 {
77 //if the selection is fully selected, commit the current session
78 if (m_session.SelectedCompletionSet.SelectionStatus.IsSelected)
79 {
80 m_session.Commit();
81 //also, don't add the character to the buffer
82 return VSConstants.S_OK;
83 }
84 else
85 {
86 //if there is no selection, dismiss the session
87 m_session.Dismiss();
88 }
89 }
90 }
91
92 //pass along the command so the char is added to the buffer
93 int retVal = m_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
94 bool handled = false;
95 if (!typedChar.Equals(char.MinValue) && char.IsLetterOrDigit(typedChar))
96 {
97 if (m_session == null || m_session.IsDismissed) // If there is no active session, bring up completion
98 {
99 this.TriggerCompletion();
100 m_session.Filter();
101 }
102 else //the completion session is already active, so just filter
103 {
104 m_session.Filter();
105 }
106 handled = true;
107 }
108 else if (commandID == (uint)VSConstants.VSStd2KCmdID.BACKSPACE //redo the filter if there is a deletion
109 || commandID == (uint)VSConstants.VSStd2KCmdID.DELETE)
110 {
111 if (m_session != null && !m_session.IsDismissed)
112 m_session.Filter();
113 handled = true;
114 }
115 if (handled) return VSConstants.S_OK;
116 return retVal;
117 }
118 private bool TriggerCompletion()
119 {
120 //the caret must be in a non-projection location
121 SnapshotPoint? caretPoint =
122 m_textView.Caret.Position.Point.GetPoint(
123 textBuffer => (!textBuffer.ContentType.IsOfType("projection")), PositionAffinity.Predecessor);
124 if (!caretPoint.HasValue)
125 {
126 return false;
127 }
128
129 m_session = m_provider.CompletionBroker.CreateCompletionSession
130 (m_textView,
131 caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive),
132 true);
133
134 //subscribe to the Dismissed event on the session
135 m_session.Dismissed += this.OnSessionDismissed;
136 m_session.Start();
137
138 return true;
139 }
140 private void OnSessionDismissed(object sender, EventArgs e)
141 {
142 m_session.Dismissed -= this.OnSessionDismissed;
143 m_session = null;
144 }
145 }
146 }
Deleted XFEExtension.NetCore.VSIX/XFEExtensionCompletionHandlerProvider.cs +0 -34
@@ -1,34 +0,0 @@
1 using Microsoft.VisualStudio.Editor;
2 using Microsoft.VisualStudio.Language.Intellisense;
3 using Microsoft.VisualStudio.Shell;
4 using Microsoft.VisualStudio.Text.Editor;
5 using Microsoft.VisualStudio.TextManager.Interop;
6 using Microsoft.VisualStudio.Utilities;
7 using System;
8 using System.Composition;
9
10 namespace XFEExtension.NetCore.VSIX
11 {
12 [Export(typeof(IVsTextViewCreationListener))]
13 [Name("token completion handler")]
14 [ContentType("plaintext")]
15 [TextViewRole(PredefinedTextViewRoles.Editable)]
16 internal class XFEExtensionCompletionHandlerProvider : IVsTextViewCreationListener
17 {
18 [Import]
19 internal IVsEditorAdaptersFactoryService AdapterService { get; set; } = null;
20 [Import]
21 internal ICompletionBroker CompletionBroker { get; set; }
22 [Import]
23 internal SVsServiceProvider ServiceProvider { get; set; }
24 public void VsTextViewCreated(IVsTextView textViewAdapter)
25 {
26 ITextView textView = AdapterService.GetWpfTextView(textViewAdapter);
27 if (textView == null)
28 return;
29
30 Func<XFEExtensionCompletionCommandHandler> createCommandHandler = delegate () { return new XFEExtensionCompletionCommandHandler(textViewAdapter, textView, this); };
31 textView.Properties.GetOrCreateSingletonProperty(createCommandHandler);
32 }
33 }
34 }
Deleted XFEExtension.NetCore.VSIX/XFEExtensionCompletionSource.cs +0 -55
@@ -1,55 +0,0 @@
1 using Microsoft.VisualStudio.Language.Intellisense;
2 using Microsoft.VisualStudio.Text;
3 using Microsoft.VisualStudio.Text.Operations;
4 using System;
5 using System.Collections.Generic;
6
7 namespace XFEExtension.NetCore.VSIX
8 {
9 internal class XFEExtensionCompletionSource : ICompletionSource
10 {
11 private XFEExtensionCompletionSourceProvider m_sourceProvider;
12 private ITextBuffer m_textBuffer;
13 private List<Completion> m_compList;
14 public XFEExtensionCompletionSource(XFEExtensionCompletionSourceProvider sourceProvider, ITextBuffer textBuffer)
15 {
16 m_sourceProvider = sourceProvider;
17 m_textBuffer = textBuffer;
18 }
19 void ICompletionSource.AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets)
20 {
21 List<string> strList = new List<string>();
22 strList.Add("addition");
23 strList.Add("adaptation");
24 strList.Add("subtraction");
25 strList.Add("summation");
26 m_compList = new List<Completion>();
27 foreach (string str in strList)
28 m_compList.Add(new Completion(str, str, str, null, null));
29
30 completionSets.Add(new CompletionSet(
31 "Tokens", //the non-localized title of the tab
32 "Tokens", //the display title of the tab
33 FindTokenSpanAtPosition(session.GetTriggerPoint(m_textBuffer),
34 session),
35 m_compList,
36 null));
37 }
38 private ITrackingSpan FindTokenSpanAtPosition(ITrackingPoint point, ICompletionSession session)
39 {
40 SnapshotPoint currentPoint = (session.TextView.Caret.Position.BufferPosition) - 1;
41 ITextStructureNavigator navigator = m_sourceProvider.NavigatorService.GetTextStructureNavigator(m_textBuffer);
42 TextExtent extent = navigator.GetExtentOfWord(currentPoint);
43 return currentPoint.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive);
44 }
45 private bool m_isDisposed;
46 public void Dispose()
47 {
48 if (!m_isDisposed)
49 {
50 GC.SuppressFinalize(this);
51 m_isDisposed = true;
52 }
53 }
54 }
55 }
Deleted XFEExtension.NetCore.VSIX/XFEExtensionCompletionSourceProvider.cs +0 -22
@@ -1,22 +0,0 @@
1 using Microsoft.VisualStudio.Language.Intellisense;
2 using Microsoft.VisualStudio.Text;
3 using Microsoft.VisualStudio.Text.Operations;
4 using Microsoft.VisualStudio.Utilities;
5 using System.Composition;
6 using System.Threading.Tasks;
7
8 namespace XFEExtension.NetCore.VSIX
9 {
10 [Export(typeof(ICompletionSourceProvider))]
11 [ContentType("plaintext")]
12 [Name("token completion")]
13 internal class XFEExtensionCompletionSourceProvider : ICompletionSourceProvider
14 {
15 [Import]
16 internal ITextStructureNavigatorSelectorService NavigatorService { get; set; }
17 public ICompletionSource TryCreateCompletionSource(ITextBuffer textBuffer)
18 {
19 return new XFEExtensionCompletionSource(this, textBuffer);
20 }
21 }
22 }
Deleted XFEExtension.NetCore.VSIX/XFEExtensionSnippets/XFESnippets.xml +0 -12
@@ -1,12 +0,0 @@
1 <?xml version="1.0" encoding="utf-8" ?>
2 <SnippetCollection>
3 <Language Lang="XFESnippets" Guid="{26e90afd-9260-4229-819a-61538e0198f7}">
4 <SnippetDir>
5 <OnOff>On</OnOff>
6 <Installed>true</Installed>
7 <Locale>1033</Locale>
8 <DirPath>%InstallRoot%\XFEExtensionSnippets\CodeSnippets\</DirPath>
9 <LocalizedName>Snippets</LocalizedName>
10 </SnippetDir>
11 </Language>
12 </SnippetCollection>
Modified XFEExtension.NetCore.VSIX/source.extension.vsixmanifest +7 -1
@@ -4,10 +4,16 @@
4 4 <Identity Id="XFEExtension.NetCore.VSIX.26e90afd-9260-4229-819a-61538e0198f7" Version="1.0" Language="zh-CN" Publisher="XFEstudio" />
5 5 <DisplayName>XFEExtension.NetCore.VSIX</DisplayName>
6 6 <Description xml:space="preserve">A Extension VSIX package based on the XFEExtenison.NetCore Nuget Package</Description>
7 <License>LICENSE.txt</License>
8 <ReleaseNotes>ReleaseNotes.txt</ReleaseNotes>
9 <Icon>logoIcon.png</Icon>
10 <PreviewImage>preview1.png</PreviewImage>
11 <Tags>XFE;XFEExtension;Code;Snippet;</Tags>
12 <Preview>true</Preview>
7 13 </Metadata>
8 14 <Installation>
9 15 <InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0, 18.0)">
10 <ProductArchitecture>amd64</ProductArchitecture>
16 <ProductArchitecture>x86</ProductArchitecture>
11 17 </InstallationTarget>
12 18 </Installation>
13 19 <Dependencies>