{"id":3014,"date":"2024-12-19T05:05:11","date_gmt":"2024-12-19T10:05:11","guid":{"rendered":"https:\/\/blogs.mathworks.com\/matlab\/?p=3014"},"modified":"2024-12-19T05:05:11","modified_gmt":"2024-12-19T10:05:11","slug":"debugging-support-in-the-matlab-extension-for-visual-studio-code","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/matlab\/2024\/12\/19\/debugging-support-in-the-matlab-extension-for-visual-studio-code\/","title":{"rendered":"Debugging support in the MATLAB extension for Visual Studio Code"},"content":{"rendered":"<div class = rtcContent><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Since its April 2023 launch, the MATLAB extension for Visual Studio Code has been extremely popular with<\/span><a href = \"https:\/\/marketplace.visualstudio.com\/items?itemName=MathWorks.language-matlab\" target=\"_blank\"><span> over 329,000 installs via the Visual Studio Marketplace<\/span><\/a><span> at the time of writing. Our development approach to this extension has been to release early and often, responding to <\/span><a href = \"https:\/\/github.com\/mathworks\/MATLAB-extension-for-vscode\/issues\" target=\"_blank\"><span>feedback from the community<\/span><\/a><span> as we go.<\/span><\/div><h2  style = 'margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>You asked for debugging support for MATLAB in Visual Studio Code<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>One of the most common pieces of feedback we received was that you wanted debugging support as soon as possible. Royi Avital was the first user to open up a <\/span><a href = \"https:\/\/github.com\/mathworks\/MATLAB-extension-for-vscode\/issues\/103\" target=\"_blank\"><span>GitHub issue with the feature request<\/span><\/a><span> but many other people added thumbs ups and other comments which served to show us how important this feature is to you. <\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"http:\/\/blogs.mathworks.com\/matlab\/files\/2024\/12\/VSCodeDebug_1.png\" width = \"500\" height = \"223\" alt = \"\" style = \"vertical-align: baseline; width: 500px; height: 223px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>One of these comments, from GitHub user fspinar made our day.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"http:\/\/blogs.mathworks.com\/matlab\/files\/2024\/12\/VSCodeDebug_2.png\" width = \"502\" height = \"208\" alt = \"\" style = \"vertical-align: baseline; width: 502px; height: 208px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Positive feedback like this, combined with a clear set of feature requests are extremely motivating for the development team.<\/span><\/div><h2  style = 'margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>So we gave you debugging support for MATLAB in Visual Studio Code<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Let's start with a piece of code I am noodling around with right now. I can open and run it in Visual Studio Code and have been able to do this since the March 2024 release.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"http:\/\/blogs.mathworks.com\/matlab\/files\/2024\/12\/VSCodeDebug_3.gif\" width = \"1004\" height = \"649\" alt = \"VSCodeDebug1.gif\" style = \"vertical-align: baseline; width: 1004px; height: 649px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>With the latest version, released this week, I can add breakpoints to pause code execution. When I run the code I can view the values of variables in the \u201cVariables\u201d section of the \u201cRun and Debug\u201d view, execute code in the MATLAB terminal and hover my mouse over variables in the editor to see their value right now. All of the usual debugging controls are there including Continue, Step Over, Step Into, Step Out, Restart and Stop.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"http:\/\/blogs.mathworks.com\/matlab\/files\/2024\/12\/VSCodeDebug_4.gif\" width = \"1007\" height = \"651\" alt = \"VSCodeDebug2.gif\" style = \"vertical-align: baseline; width: 1007px; height: 651px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Conditional breakpoints are also supported. Right click on the line number you want to set a conditional break point and select it from the resulting context menu. Add the condition, press Enter and then run the code. In the following video, I ask it to break every 200 iterations and take a look at the plot after the first set of 200.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"http:\/\/blogs.mathworks.com\/matlab\/files\/2024\/12\/VSCodeDebug_5.gif\" width = \"1007\" height = \"651\" alt = \"VSCodeDebug3.gif\" style = \"vertical-align: baseline; width: 1007px; height: 651px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>With that I think we've satisfied the three points in Royi's feature request. There are a couple of things that don't work yet that the team are aware of such as logpoints and triggered breakpoints. If either of these things are issues for you then please join the <\/span><a href = \"https:\/\/github.com\/mathworks\/MATLAB-extension-for-vscode\" target=\"_blank\"><span>discussion over at the GitHub issues page for the extension<\/span><\/a><span>.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>I encourage you to try out this latest version, let us know how you get on and tell us what you'd like to see next in the MATLAB extension for Visual Studio Code! <\/span><\/div><h2  style = 'margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>Resources and further reading<\/span><\/h2><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><a href = \"https:\/\/marketplace.visualstudio.com\/items?itemName=MathWorks.language-matlab\" target=\"_blank\"><span>MATLAB extension for Visual Studio Code<\/span><\/a><span> on the Visual Studio Marketplace.<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><a href = \"https:\/\/github.com\/mathworks\/MATLAB-extension-for-vscode\" target=\"_blank\"><span>MATLAB-extension-for-vscode<\/span><\/a><span> GitHub repository for the extension.<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><a href = \"https:\/\/blogs.mathworks.com\/matlab\/2024\/03\/05\/matlab-extension-for-visual-studio-code-now-with-code-execution\/\"><span>MATLAB extension for Visual Studio Code: Now with code execution<\/span><\/a><span> The second blog post about the extension.<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><a href = \"https:\/\/blogs.mathworks.com\/matlab\/2023\/04\/26\/do-you-use-visual-studio-code-matlab-is-now-there-too\/\"><span>Do you use Visual Studio Code? MATLAB is now there too<\/span><\/a><span> The first blog post about the extension.<\/span><\/li><\/ul>\n<\/div><script type=\"text\/javascript\">var css = ''; var head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); head.appendChild(style); style.type = 'text\/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); }<\/script>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/matlab\/files\/2024\/12\/VSCodeDebug_4.gif\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>Since its April 2023 launch, the MATLAB extension for Visual Studio Code has been extremely popular with over 329,000 installs via the Visual Studio Marketplace at the time of writing. Our... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/matlab\/2024\/12\/19\/debugging-support-in-the-matlab-extension-for-visual-studio-code\/\">read more >><\/a><\/p>","protected":false},"author":176,"featured_media":3005,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[20,64],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/posts\/3014"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/users\/176"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/comments?post=3014"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/posts\/3014\/revisions"}],"predecessor-version":[{"id":3017,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/posts\/3014\/revisions\/3017"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/media\/3005"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/media?parent=3014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/categories?post=3014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/tags?post=3014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}