GithubHelp home page GithubHelp logo

insertguid's Introduction

Insert new Guid command

Build

Makes it super easy to insert a new GUID into any editor and input field.

Insert a new GUID by invoking the command under the Edit top-level menu or hit CTRL+K,Space. The Insert Guid command is also available in the context-menu of documents.

Command

How can I help?

If you enjoy using the extension, please give it a ★★★★★ rating on the Visual Studio Marketplace.

Should you encounter bugs or if you have feature requests, head on over to the GitHub repo to open an issue if one doesn't already exist.

Pull requests are also very welcome, since I can't always get around to fixing all bugs myself. This is a personal passion project, so my time is limited.

Another way to help out is to sponsor me on GitHub.

insertguid's People

Contributors

madskristensen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

insertguid's Issues

Configurable GUID format

I haven't played with writing extensions, so I'm not sure about the level of difficulty. I'm sure that branching my own variant to hardcode a new style would be straight-forward. But, I thought I'd throw this configurable idea out there for anyone interested.

What if there was a configuration option (in Tools -> Options) that allowed you to define the pasted format?
The format could be as simple as string interpolation style with an assumed variable named guid. (Or String.Format style using {0} instead)

{guid} (default format) would result in
BF9DE515-9522-4941-962D-955B0AF81FAF

new Guid("{guid}"); would result in
new Guid("BF9DE515-9522-4941-962D-955B0AF81FAF");

You could always add multiple formats with multiple menu items and default hotkeys...if you wanted to go all in. Like a more convenient version of the old Create Guid utility.

Command not supported in Windows Installer XML (Wix) projects

Issue #2 mentions that this extension can't be used in an F# project, with VS advising The key combination (Ctrl+K, Ctrl+Space) is bound to command (Insert Guid) which is not currently available.

The same goes for Wix Toolset projects (*.wixproj). Which is a shame, because this is where I have to enter new GUIDs constantly.

Originally posted by @uceumern in #2 (comment)

The issue was closed as commit 27fc2e5 added support for all languages.

Unfortunately, it still doesn't work for *.wixproj projects. As per the quoted post, we're inserting GUIDs willy-nilly in these projects, and this extension would be a huge help.

Support multi-caret by using a unique GUID on each line

I often need to insert multiple guids on different lines. I was hoping that the extension would produce unique guids on each line but instead it inserted the same guid multiple times.

I would like it to produce a unique guid on each editor caret.

Command not available in F# project

When I try to use the key combination to generate a new Guid while in a F# project I get the message The key combination (Ctrl+K, Ctrl+Space) is bound to command (Insert Guid) which is not currently available. Is this extension not supported in F# projects?

Thank you!

Invalid MEF cache => could not load type

4547 2021/06/07 00:50:39.392 Error Microsoft.VisualStudio.ComponentModelHost.VsShellComponentModelHost An invalid MEF cache has been found due to a mismatching timestamp or MVID: Microsoft.VisualStudio.ExtensibilityHosting.InvalidMEFCacheException: The Visual Studio component cache is out of date (assembly: InsertGuid, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null). Please restart Visual Studio.;VS.Platform.ExtensibilityHosting.MefCacheInvalidation.LoadedAssembly.Name=InsertGuid, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null;VS.Platform.ExtensibilityHosting.MefCacheInvalidation.LoadedAssembly.CodeBase=file:///c:/users/john/appdata/local/microsoft/visualstudio/16.0_ba1a16a5/extensions/ctdat30z.pzx/InsertGuid.dll;VS.Platform.ExtensibilityHosting.MefCacheInvalidation.ActualTimestamp=637584529249026387;VS.Platform.ExtensibilityHosting.MefCacheInvalidation.ExpectedTimestamp=636914458776541083;VS.Platform.ExtensibilityHosting.MefCacheInvalidation.ActualMVID=22618d7f-f473-4e8e-a909-e3f32ebd91eb;VS.Platform.ExtensibilityHosting.MefCacheInvalidation.ExpectedMVID=5c163a80-2893-4d6e-b9f0-25098226fb71 4548 2021/06/07 00:50:39.394 Error Microsoft.VisualStudio.ComponentModelHost.VsShellComponentModelHost A MEF Component threw an exception at runtime: System.TypeLoadException: Could not load type 'InsertGuid.Commands.InsertGuidCommand' from assembly 'InsertGuid, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. at System.Reflection.RuntimeModule.GetType(RuntimeModule module, String className, Boolean ignoreCase, Boolean throwOnError, ObjectHandleOnStack type) at System.Reflection.RuntimeModule.GetType(String className, Boolean throwOnError, Boolean ignoreCase) at Microsoft.VisualStudio.Composition.Reflection.TypeRef.get_ResolvedType() at Microsoft.VisualStudio.Composition.Reflection.ResolverExtensions.Resolve(MethodRef methodRef) at Microsoft.VisualStudio.Composition.Reflection.MethodRef.Resolve() at Microsoft.VisualStudio.Composition.Reflection.MemberRef.get_MemberInfo() at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.CreateValue() at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.Create() at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveNext(PartLifecycleState nextState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose() at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.<>c__DisplayClass15_0.<GetExportedValueHelper>b__0() 4549 2021/06/07 00:50:39.624 Error Editor or Editor Extension System.TypeLoadException: Could not load type 'InsertGuid.Commands.InsertGuidCommand' from assembly 'InsertGuid, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. at System.Reflection.RuntimeModule.GetType(RuntimeModule module, String className, Boolean ignoreCase, Boolean throwOnError, ObjectHandleOnStack type) at System.Reflection.RuntimeModule.GetType(String className, Boolean throwOnError, Boolean ignoreCase) at Microsoft.VisualStudio.Composition.Reflection.TypeRef.get_ResolvedType() at Microsoft.VisualStudio.Composition.Reflection.ResolverExtensions.Resolve(MethodRef methodRef) at Microsoft.VisualStudio.Composition.Reflection.MethodRef.Resolve() at Microsoft.VisualStudio.Composition.Reflection.MemberRef.get_MemberInfo() at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.CreateValue() at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.Create() at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveNext(PartLifecycleState nextState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose() at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.<>c__DisplayClass15_0.<GetExportedValueHelper>b__0() --- End of stack trace from previous location where exception was thrown --- at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.<>c__DisplayClass15_0.<GetExportedValueHelper>b__0() at Microsoft.VisualStudio.Composition.DelegateServices.<>c__DisplayClass2_0`1.<As>b__0() at System.Lazy`1.CreateValue() at System.Lazy`1.LazyInitValue() at System.Lazy`1.get_Value() at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.InstantiateExtension[TExtension](Object errorSource, Lazy`1 provider) --- End of stack trace from previous location where exception was thrown --- at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

Encode string to GUID

Is your feature request related to a problem? Please describe.
Bit encoders to turn strings into consistent GUIDs. Tried modifying your base code to manage the insert but keep running into VSIX and "Not registered" issues for the add-in - Cloned Community.VisualStudio.Toolkit.17.0 as a reference but in 22 still having issues with the GUID not found (GUID is the add-in the Mads GUID Creator/Inserter)

Describe the solution you'd like
Select text to convert a 5-bit or 6-bit encoded GUID for consistency and identification and reuse. If no text is selected, prompt with a character-limited input box.

Describe alternatives you've considered
Downloaded this GIT and am figuring out the interface to do this in VS.Community.

Additional context
Updated to CS format for 5, 6, 7, 8-bit formats. 6-bit is the most common to have the entire alphabet +Numbers and some symbols.

`using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GUID_Encode
{
public struct CharBit //Character bit struct
{
public string Characters { get; }
public int BitSize { get; }

    public CharBit(string characters, int bitSize)
    {
        Characters = characters;
        BitSize = bitSize;
    }
}   // Define the character BaseBits and their corresponding bit sizes
public class CharBits               //encode/decode keys
{   // Structure to store base information string of encrypt characters and relevant bitsize
    //internal static string Bin_In="";             //References for debugging and checking BIN IN and BIN OUT; commented out below.
    // static string Bin_Out="";                    //References for debugging and checking BIN IN and BIN OUT; commented out below.

    public static readonly CharBit[] Key =         //DEFINE CONSTANT ARRAYS FOR INPUT/OUTPUT BSAED ON LETTERS
    {
    //GUID is a 128 bit integer--------------------------------------------------------------------------------------
    // 'do not change strings - will match through bit compresion and will change the whole field base encoding!
    // '5 Bit - Simplified - ignoring upper and lower case
    // '5 bit - would allow for names (128bitGUID/5bit=)25 characters long - 2^5(32) character positions available 
    // 'REQUIRES UCASE convert prior to checking. can contain a few digits only
    // 'Optional simpler base 5bit- not used - do not change this - it will change the whole field base and compression!
    // ''''''''''0'''''''''1'''''''''2'''''''''3'*< length of 32 chars MAX (32 positions available)
    // ''''''''''01234567890123456789012345678901 ''NoSpaces! IGNORE case for encode/decode
    new CharBit(".ABCDEFGHIJKLMNOPQRSTUVWXYZ_1234", 5),
    // <6-bit is default>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    // '6 bit - allows for names (128bitGUID/6bit=)21 characters long - 2^6(64) character positons available CASE matters in revit parameters foo is different from FOO
    // 'do not change this - it will change the whole field base and compression!
    // ''''''''''0'''''''''1'''''''''2'''''''''3'''''''''4'''''''''5'''''''''6''''
    // ''''''''''0123456789012345678901234567890123456789012345678901234567890123  ''NoSpaces!
    new CharBit(".ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789abcdefghijklmnopqrstuvwxyz", 6),
    // 'Encoding bitsize
    // ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    // '7 bit - allow for names (128bitGUID/7bit=)18 characters long
    // 'do not change this - it will change the whole field base and compression!
    // ''''''''''0'''''''''1'''''''''2'''''''''3'''''''''4'''''''''5'''''''''6'''''''''7'''''''''''12      *<127
    // ''''''''''01234567890123456789012345678901234567890123456789012345678901234567890123456789---01234567
    new CharBit(".ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789abcdefghijklmnopqrstuvwxyz !\"#$%&'()*+", 7),
    // 'Encoding bitsize
    // ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    // '8 bit - allows for (128bitGUID/8bit=)16 characters but uses all 255 characters and symbvols available.
    // 'Same as straight hex encoding xFF 256 bits - mostly 173 wasted spaces
    // ''''''''''0'''''''''1'''''''''2'''''''''3'''''''''4'''''''''5'''''''''6'''''''''7'''''''''8'''
    // ''''''''''012345678901234567890123456789012345678901234567890123456789012345678901234567890123
    new CharBit(".ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789abcdefghijklmnopqrstuvwxyz !\"#$%&'()*+:;=@^`", 8)
    };
}
public class GUID_Encode            //Entry point to encode GUIDs <<<<<<<<START<<<<<<<<<<<<<<<<
{

    public static bool GUIDMatches(Guid gGUID, string strVarName, int BitLimit = 5) //Checks if GUID Matches varname in BitLimit
    {
        bool Matches = (gGUID == StringToGUID(strVarName, BitLimit));
        return (Matches);
    }
    public static System.Guid StringToGUID(string strVarName, int BitLimit = 5)   //Default bit limit is 5
    {
        if (BitLimit > 8)
        {
            BitLimit = 8;       //not more than 8 bits
        }
        if (BitLimit < 5)
        {
            BitLimit = 5;       //not less than 5 bits
        }
        if (BitLimit == 5)      //To Uppercase for 5 bit limited character set
        {
            strVarName = strVarName.ToUpper();
        }                                                   //5-bit all caps
        int NumChar = 128 / BitLimit;                       //Calculate max length of names with bit packing
        strVarName = strVarName.PadRight(NumChar, '.');     //Pad with .
        strVarName = strVarName.Substring(0, NumChar);      //chop off excessive characters in name to meet characters VS bitsize requirements
        return String_To_GUID(strVarName, BitLimit);        //new Guid(strGUID);
    }

    //private static string String_to_6Bit2HexGUID(string varName)
    private static System.Guid String_To_GUID(string varName, int BitLimit = 5)
    {
        CharBit cb = CharBits.Key[BitLimit - 5]; //for bit limit 5-8
        string strGUID = string.Empty;
        string strBin = string.Empty;
        string strBit = string.Empty;
        //long LongBit;
        if (BitLimit == 5)                                          //Redundant ToUpper for 5 bit a precaution
        {
            varName = varName.ToUpper();
        }
        for (int i = 0; i < varName.Length; i++)
        {
            char c = varName.Substring(i, 1)[0];                    //single character
            int cpos = cb.Characters.IndexOf(c);                    //index position of character to max char in set //-1 if not found
            if (cpos == -1)
            {
                cpos = cb.Characters.IndexOf('.');                  //reset to '.' character as a replacement for not found.
            }
            strBit = Dec2Bin(cpos, BitLimit);                       //from charbits return position of character
            strBin = strBit + strBin;                               //Most dignificant bits at left so prepend values
        }
        //CharBits.Bin_In = strBin;
        strBin = strBin.PadLeft(128, '0');                            //pad out additional MSBs with 0's in odd-bit sizes
        //CharBits.Bin_In = strBin;
        return Str128BinaryToGuid(strBin);
    }

    private static string Dec2Bin(long longIn, int BitLimit = 5) //convert to BitLimit-bit to pack bits. This is the bit chunk for the out later.
    {
        string dec2Bin = "";
        longIn = (long)Math.Floor(Convert.ToDecimal(longIn));
        while (longIn != 0)
        {
            dec2Bin = $"{longIn - 2 * (long)(longIn / 2)}{dec2Bin}";
            longIn = (long)(longIn / 2);
        }

        if (dec2Bin.Length > BitLimit)
        {
            dec2Bin = "Error - Number exceeds specified bit size";
        }

        dec2Bin = $"{dec2Bin.PadLeft(BitLimit, '0')}";  //string is pack with the number of bits in bit limit MSB-Left

        return dec2Bin;
    }

    private static Guid Str128BinaryToGuid(string binaryString)
    {//Output was failing to match in 1st half od BIN str from GUID
     //The issue lies in the byte order of the Guid structure. The Guid structure stores the bytes in
     //little-endian format, which means the byte order needs to be reversed when converting to and from binary.
        binaryString = binaryString.PadLeft(128, '0');

        ulong high = Convert.ToUInt64(binaryString.Substring(0, 64), 2);
        ulong low = Convert.ToUInt64(binaryString.Substring(64), 2);

        byte[] bytes = new byte[16];
        BitConverter.GetBytes(high).CopyTo(bytes, 0);
        BitConverter.GetBytes(low).CopyTo(bytes, 8);
        Array.Reverse(bytes);                           // Reverse the byte order to match little-endian format

        Guid gGUID = new Guid(bytes);
        return gGUID;
    }

    public static string GUIDtoString(Guid gGUID, int BitLimit = 5)   //Default bit limit is 5
    {
        if (BitLimit > 8) BitLimit = 8;  //not more than 8 bits
        if (BitLimit < 5) BitLimit = 5;  //not less than 5 bits

        ///return new Guid(strGUID);
        return GUID_To_String(gGUID, BitLimit);
    }

    private static string GUID_To_String(Guid gGUID, int BitLimit = 5)
    {
        CharBit cb = CharBits.Key[BitLimit - 5]; //for bit limit 5-8
        string strBin = string.Empty;
        string strByte;
        string strVarName = string.Empty;
        int pos;

        strBin = GuidToStr128Bin(gGUID);        //convert to binary. Matches finally! The Guid structure stores the bytes in
                                                //CharBits.Bin_Out = strBin;
        string ss = strBin;

        while (ss.Length >= BitLimit) // Stop when remaining string length is less than BitLimit
        {
            strByte = ss.Substring(ss.Length - BitLimit);
            ss = ss.Substring(0, ss.Length - strByte.Length);
            pos = Convert.ToInt32(strByte, 2);
            strVarName += cb.Characters[pos];
        }

        return strVarName;
    }

    private static string GuidToStr128Bin(Guid gGUID)
    {
        byte[] bytes = gGUID.ToByteArray();
        Array.Reverse(bytes); // Reverse the byte order to match little-endian format

        ulong high = BitConverter.ToUInt64(bytes, 0);
        ulong low = BitConverter.ToUInt64(bytes, 8);

        string binaryString = Convert.ToString((long)high, 2).PadLeft(64, '0') + Convert.ToString((long)low, 2).PadLeft(64, '0');
        return binaryString;
    }
}

}
`

Key combination Ctrl+K, Ctrl+Space not available unless first used in a c# file

Describe the bug
Initially the Ctrl+K, Ctrl+Space does not work in non C# files. As soon as I press this combination in a C# file, it becomes available in other files e.g. XML, ASPX, etc.

To Reproduce
Steps to reproduce the behavior:

  1. Open a solution without C# files; e.g. a SharePoint Add-In project
  2. Open a XML or ASPX file
  3. Press Ctrl+K, Ctrl+Space
  4. See message in statusbar: The key combination (Ctrl+K, Ctrl+Space) is bound to command Insert Guid which is not currently available
  5. Add a c# file to the project
  6. Press Ctrl+K, Ctrl+Space in the new c#-file
  7. GUID gets inserted
  8. Go back to your xml or aspx file
  9. Press Ctrl+K, Ctrl+Space
  10. GUID gets inserted

Expected behavior
I expect that the command works instantly and no insertion in a c# file is needed first. It looks like the command is not initialized properly. It's very inconvenient to have to make unwanted changes to c# files or even add obsolete c# files to get this working.

Screenshots
Step to reproduce says it all; screenshots will not add more information.

Additional context
I noticed this behaviour in a SharePoint add-in project without any c#-files. The same happens in WIX files (wxs extension). As such, this bug is related to issue #4.

You explain how to insert something at the current position, but what do I do if I need to insert Guid (or whatever) at another specified position, e.g. at the very beginning? How do I navigate within the document? There seems to be no available documentation (VS 2022) nor tutorials. It would be great to expand the project, TIA.

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.