문제

할 수 있는 방법을 구현하는 지역니다.k.니다.코드 축소에 대한 자바스크립트 Visual Studio?

이 있는 경우의 수백 라인에 자바스크립트,그것은 더 이해할 수 있는 코드를 사용하여 접히는 지역으로 vb/C#.

#region My Code

#endregion
도움이 되었습니까?

해결책

여기에 블로그 항목이 설명합니다MSDN 질문.

Visual Studio 2003/2005/2008 매크로를 사용해야합니다.

Fidelity Sake를 위해 블로그 항목에서 복사 + 붙여 넣기 :

  1. 매크로 탐색기를 오픈합니다
  2. 새 매크로를 만듭니다
  3. 이름을 붙이다 OutlineRegions
  4. 매크로 편집을 클릭하고 다음 VB 코드를 붙여 넣습니다.
Option Strict Off
Option Explicit Off

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Imports System.Collections

Public Module JsMacros

    Sub OutlineRegions()
        Dim selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection

        Const REGION_START As String = "//#region"
        Const REGION_END As String = "//#endregion"

        selection.SelectAll()
        Dim text As String = selection.Text
        selection.StartOfDocument(True)

        Dim startIndex As Integer
        Dim endIndex As Integer
        Dim lastIndex As Integer = 0
        Dim startRegions As Stack = New Stack()

        Do
            startIndex = text.IndexOf(REGION_START, lastIndex)
            endIndex = text.IndexOf(REGION_END, lastIndex)

            If startIndex = -1 AndAlso endIndex = -1 Then
                Exit Do
            End If

            If startIndex <> -1 AndAlso startIndex < endIndex Then
                startRegions.Push(startIndex)
                lastIndex = startIndex + 1
            Else
                ' Outline region ...
                selection.MoveToLineAndOffset(CalcLineNumber(text, CInt(startRegions.Pop())), 1)
                selection.MoveToLineAndOffset(CalcLineNumber(text, endIndex) + 1, 1, True)
                selection.OutlineSection()

                lastIndex = endIndex + 1
            End If
        Loop

        selection.StartOfDocument()
    End Sub

    Private Function CalcLineNumber(ByVal text As String, ByVal index As Integer)
        Dim lineNumber As Integer = 1
        Dim i As Integer = 0

        While i < index
            If text.Chars(i) = vbCr Then
                lineNumber += 1
                i += 1
            End If

            i += 1
        End While

        Return lineNumber
    End Function

End Module
  1. 매크로를 저장하고 편집기를 닫습니다
  2. 이제 매크로에 바로 가기를 할당합시다. 도구-> 옵션-> 환경-> 키보드로 이동하여 "텍스트 상자가 포함 된"표시 명령에서 매크로 검색
  3. 이제 "바로 가기 키 프레스"아래 텍스트 상자에서 원하는 바로 가기를 입력 할 수 있습니다. 나는 ctrl+m+e를 사용합니다. 왜 그런지 모르겠습니다 - 방금 방금 처음 입력 한 후 지금 사용합니다 :)

다른 팁

Microsoft는 이제 확장을 가지고 있습니다 VS 2010 이 기능을 제공합니다.

JScript 편집기 확장

최신 버전의 Visual Studio와 함께 일하는 개발자에게 좋은 소식

그만큼 웹 필수품 이 기능과 함께오고 있습니다.

이것 좀 봐

enter image description here

참고 : VS 2017 사용 자바 스크립트 영역 : https://marketplace.visualstudio.com/items?itemname=madskristensen.javascriptregions

쉽게!

붕괴하려는 섹션을 표시하고

ctrl+m+h

그리고 왼쪽에 '+'마크를 사용합니다.

Visual Studio 2012를 사용하려는 사람들은 Web Essentials 2012

Visual Studio 2015를 사용하려는 사람들은 Web Essentials 2015.3

사용법은 @prasad와 똑같습니다

코드 섹션을 표시하고 (논리적 블록에 관계없이) Ctrl + M + H를 치면 선택을 접을 수 있고 확장 가능한 영역으로 정의합니다.

그만큼 Jsenhancements Visual Studio 용 플러그인이이를 잘 해결합니다.

감사합니다 0A0D 큰 대답을 위해. 나는 그것에 행운을 빕니다. Darin Dimitrov 또한 JS 파일의 복잡성을 제한하는 것에 대해 좋은 주장을합니다. 그럼에도 불구하고, 나는 그들의 정의에 대한 붕괴 기능이 파일을 통해 탐색을 훨씬 쉽게 만들 수있는 경우를 발견합니다.

일반적으로 #REGION과 관련하여 그래서 질문 그것을 잘 커버합니다.

더 고급 코드 붕괴를 지원하기 위해 매크로를 몇 가지 수정했습니다. 이 메소드는 //# 지역 키워드 ALA C# 다음에 설명을 넣을 수 있으며 다음과 같이 코드에 표시 할 수 있습니다.

예제 코드 :

//#region InputHandler
var InputHandler = {
    inputMode: 'simple', //simple or advanced

    //#region filterKeys
    filterKeys: function(e) {
        var doSomething = true;
        if (doSomething) {
            alert('something');
        }
    },
    //#endregion filterKeys

    //#region handleInput
    handleInput: function(input, specialKeys) {
        //blah blah blah
    }
    //#endregion handleInput

};
//#endregion InputHandler

업데이트 된 매크로 :

Option Explicit On
Option Strict On

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Imports System.Collections.Generic

Public Module JsMacros


    Sub OutlineRegions()
        Dim selection As EnvDTE.TextSelection = CType(DTE.ActiveDocument.Selection, EnvDTE.TextSelection)

        Const REGION_START As String = "//#region"
        Const REGION_END As String = "//#endregion"

        selection.SelectAll()
        Dim text As String = selection.Text
        selection.StartOfDocument(True)

        Dim startIndex As Integer
        Dim endIndex As Integer
        Dim lastIndex As Integer = 0
        Dim startRegions As New Stack(Of Integer)

        Do
            startIndex = text.IndexOf(REGION_START, lastIndex)
            endIndex = text.IndexOf(REGION_END, lastIndex)

            If startIndex = -1 AndAlso endIndex = -1 Then
                Exit Do
            End If

            If startIndex <> -1 AndAlso startIndex < endIndex Then
                startRegions.Push(startIndex)
                lastIndex = startIndex + 1
            Else
                ' Outline region ...
                Dim tempStartIndex As Integer = CInt(startRegions.Pop())
                selection.MoveToLineAndOffset(CalcLineNumber(text, tempStartIndex), CalcLineOffset(text, tempStartIndex))
                selection.MoveToLineAndOffset(CalcLineNumber(text, endIndex) + 1, 1, True)
                selection.OutlineSection()

                lastIndex = endIndex + 1
            End If
        Loop

        selection.StartOfDocument()
    End Sub

    Private Function CalcLineNumber(ByVal text As String, ByVal index As Integer) As Integer
        Dim lineNumber As Integer = 1
        Dim i As Integer = 0

        While i < index
            If text.Chars(i) = vbLf Then
                lineNumber += 1
                i += 1
            End If

            If text.Chars(i) = vbCr Then
                lineNumber += 1
                i += 1
                If text.Chars(i) = vbLf Then
                    i += 1 'Swallow the next vbLf
                End If
            End If

            i += 1
        End While

        Return lineNumber
    End Function

    Private Function CalcLineOffset(ByVal text As String, ByVal index As Integer) As Integer
        Dim offset As Integer = 1
        Dim i As Integer = index - 1

        'Count backwards from //#region to the previous line counting the white spaces
        Dim whiteSpaces = 1
        While i >= 0
            Dim chr As Char = text.Chars(i)
            If chr = vbCr Or chr = vbLf Then
                whiteSpaces = offset
                Exit While
            End If
            i -= 1
            offset += 1
        End While

        'Count forwards from //#region to the end of the region line
        i = index
        offset = 0
        Do
            Dim chr As Char = text.Chars(i)
            If chr = vbCr Or chr = vbLf Then
                Return whiteSpaces + offset
            End If
            offset += 1
            i += 1
        Loop

        Return whiteSpaces
    End Function

End Module

이것은 현재 VS2017에 기본적으로 있습니다.

//#region fold this up

//#endregion

//와 # 사이의 공백은 중요하지 않습니다.

Changelogs에서 언급을 찾을 수 없으므로 이것이 어떤 버전을 추가했는지 모릅니다. v15.7.3에서 사용할 수 있습니다.

VS 2012 및 vs 2015에서 Webestentials 플러그인을 설치하면 그렇게 할 수 있습니다.

http://vswebestentials.com/features/javaScript

사용중인 경우 resharper

이 사진의 단계를 허용합니다

enter image description here그런 다음 템플릿 편집기에 이것을 작성하십시오

  //#region $name$
$END$$SELECTION$
  //#endregion $name$

그리고 이름을 지정하십시오 #region 이 그림에서와 같이enter image description here

이것이 당신에게 도움이되기를 바랍니다

이 답변 중 어느 것도 Visual Studio 2017에서 나에게 효과가 없었습니다.

VS 2017을위한 최고의 플러그인 : 자바 스크립트 영역

Example 1:

enter image description here

Example 2:

enter image description here

테스트 및 승인 :

enter image description here

Visual Studio 2017 용.

    //#region Get Deactivation JS
    .
    .
    //#endregion Get Deactivation JS

이것은 일찍 작동하지 않았으므로 Extension을 다운로드했습니다. 여기

지역없이 작동 변경 설정

//#region Optional Naming
    var x = 5 -0; // Code runs inside #REGION
    /* Unnecessary code must be commented out */
//#endregion

를 사용하 붕괴되는 코멘트 지역/**/

/* Collapse this

*/

설정->검색"접"->편집기:접는 전략->"자동"에서"들여쓰기".

태그:Node.js 및 라이브러리 노드 js Javascript ES5ECMAScript 주석 접히는 숨기고 지역 Visual studio 코드 vscode2018 년 version1.2+ https://code.visualstudio.com/updates/v1_17#_folding-regions

VS뿐만 아니라 거의 모든 편집자를위한 것입니다.

(function /* RegionName */ () { ... })();

경고: 범위와 같은 단점이 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top