Code Generation / Auto Complete in Xamarin Studio

MSFXMSFX GBMember
edited October 2013 in Visual Studio

I used to use FlashDevelop alot as my last coding IDE and it had some incredible shortcuts for code completion and generation and i'm hoping that Xamarin has the same somewhere hidden...

For example if I typed the name of a variable/function and pressed Ctrl+Shift+1 which would provide options to either make it a public var or a function and then would autocomplete the definition of that variable/function for you.

Anyone know anything like the above or where I can make custom key bindings?

You can see the Code Generation features of FlashDevelop here..

Thanks,
Matt

Posts

  • mhutchmhutch USMember, Xamarin Team Xamurai

    Try Alt-Enter to access Quick Fixes and Context Actions. They're also in the source editor's context menu.

    There are a few other things you might want to look at:

    • Find and edit key bindings at Preferences -> Environment -> Keybindings.
    • Search commands, files, types etc in the global search in the toolbar. Quickly open it with Command-. (Mac) or Control-, (Windows).
    • Automatically find and highlight potential problems with source analysis. Enable it with Preferences -> Text Editor -> Source Analysis -> Enable analysis of open files. Access the fixes with Alt-Enter.
    • Automatically import types from any namespace with the Import Type command, Control-Alt-Enter. Or always show these items in the completion lists with Preferences -> Text Editor -> Completion behavior -> Show Import Items.
    • Use the contextual code generator to generate members and statements, Edit -> Show Code Generation Window.

    I'd also suggest you watch my Evolve talk on Getting the most out of Xamarin Studio.

  • MSFXMSFX GBMember

    ah, that's exactly what I was looking for with your first point - thanks so much!

    I've got a couple of things i've found that are bugging me, you may be able to help..?

    1) With snippets, say a for loop, I type "for" and then press tab to use the snippet but it tabs the snippet 3 tab breaks across the page... why is that? How can I stop it doing this? It also doesn't use the changes I made to the snippet in my preferences...? My code snippet for a for loop has the brace on the next line whereas it still places it on the same line as the for statement...?

    2) Kind of related to the above. At the end of a line if I add a semicolon it suddenly tabs the whole line over by 3 tab breaks?? Why does it do this and how can I stop this?

    3) How can I stop spaces being added inbetween a method name / call and the brackets? I.e. I want "Test()" not "Test ()"?

    Otherwise it's a lovely snappy editor :)

    Thanks!

  • MSFXMSFX GBMember

    Another query I have is when you press Cmd-D to go to a declaration, is there a command to take you back to where you were? That would be nice :)

  • Preferences / Key Bindings / Search: Navigate Back. I've changed my shortcut, that's why I can't tell you the original one (I believe it is Ctrl-Cmd-Left).

  • mhutchmhutch USMember, Xamarin Team Xamurai

    All 3 issues are your code formatting settings. The on-the-fly formatter formats code to match your settings as you type. Note that these settings are a per-solution policy.

  • MSFXMSFX GBMember

    ah, perfect!!

    it's worth noting that even if you set this in Preferences -> Source Code -> Code Formatting -> C# Source Code to Visual Studio and it's still doing all of the above and still won't wrap curly braces, lose spaces/tabbing etc you need to right click on the Project -> Options -> Source Code -> Code Formatting -> C# Source Code :)

    Thanks!

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

    @mhutch I remember you saying in a talk that you could filter down on methods/properties/events when using code completion, what was the shortcut for that again?

    Cheers

  • mhutchmhutch USMember, Xamarin Team Xamurai

    You can't filter by symbol type type but you can filter by camelCase substrings e.g. "StrBui" will match "StringBuilder". You can also use Ctrl-Space to toggle grouping by type hierarchy.

  • YuriTikhomirovYuriTikhomirov RUMember ✭✭

    About code generation... Can't find where it could be set up.
    I need to change the useful generation template from Console.WriteLine to some MyDebug.Log with the same behavior. Is that possible?

    Thanks!

  • mhutchmhutch USMember, Xamarin Team Xamurai

    @Yuri: code generator or code snippet?

    In the case of code snippets, you could add a new code snippet in Preferences. The Code Generation however is defined in code. The only way to change it would be a patched build of XS or a new addin to plug in a new generator.

Sign In or Register to comment.