오픈 소스에 기여하기 (VSCode + Spring Boot + Kotlin) - 2

Kyu0·2023년 4월 25일
0

0. 도입

살짝의 진전과 난관이 있어 해당 사항에 대해 공유 및 정리하고자 포스팅을 하게 되었습니다.


1. 진전

우선 Spring Boot 프로젝트를 열고 전체적으로 코드를 살펴본 뒤, Spring Boot Dashboard의 실행 버튼을 눌렀을 때 어떤 동작이 일어나는지 파악하기로 하고 해당 부분을 집중적으로 살펴보았습니다.

요 녀석

src/extensions.ts 파일 및 관련 파일들에 해당 동작에 대한 함수가 정의되어 있었습니다.

// src/extensions.ts
public async runBootApp(app: BootApp, debug?: boolean, profile?: string): Promise<void> {
        const mainClasData = await vscode.window.withProgress(
            { location: vscode.ProgressLocation.Window, title: `Resolving main classes for ${app.name}...` },
            async () => {
				// src/BootApp.ts
                const mainClassList = await app.getMainClasses();

                if (mainClassList && mainClassList instanceof Array && mainClassList.length > 0) {
                    return mainClassList.length === 1 ? mainClassList[0] :
                        await vscode.window.showQuickPick(mainClassList.map(x => Object.assign({ label: x.mainClass }, x)), { placeHolder: `Specify the main class for ${app.name}` });
                }
                return null;
            }
        );
        if (mainClasData === null) {
            vscode.window.showWarningMessage("No main class is found.");
            return;
        }
        if (mainClasData === undefined) {
            return;
        }

        let targetConfig = this._getLaunchConfig(mainClasData);
        if (!targetConfig) {
            targetConfig = await this._createNewLaunchConfig(mainClasData);
        }
        app.activeSessionName = targetConfig.name;

        targetConfig = await resolveDebugConfigurationWithSubstitutedVariables(targetConfig);
        app.jmxPort = parseJMXPort(targetConfig.vmArgs);

        const cwdUri: vscode.Uri = vscode.Uri.parse(app.path);
        const launchConfig = Object.assign({}, targetConfig, {
            noDebug: !debug,
            cwd: cwdUri.fsPath,
        });
        if (profile) {
            launchConfig.vmArgs = launchConfig.vmArgs + ` -Dspring.profiles.active=${profile}`;
        }

        await vscode.debug.startDebugging(
            vscode.workspace.getWorkspaceFolder(cwdUri),
            launchConfig
        );
    }
// src/BootApp.ts
    public async getMainClasses(): Promise<MainClassData[]> {
        if (this.mainClasses === undefined) {
            // Note: Command `vscode.java.resolveMainClass` is implemented in extension java-debugger
            const mainClassList = await vscode.commands.executeCommand('java.execute.workspaceCommand', 'vscode.java.resolveMainClass', this.path);
            if (mainClassList && mainClassList instanceof Array) {
                this.mainClasses = mainClassList;
            } else {
                return [];
            }
        }
        return this.mainClasses;
    }

관련 깃허브 레포지토리들을 살펴본 결과, 실제 Spring Boot 프로젝트를 실행할 때는 Debugger for Java 확장 프로그램을 의존하고 Debugger for Java는 Language Support for Java(TM) by Red hat 확장 프로그램을 의존한다는 것을 파악할 수 있었습니다.

또한, 다른 확장 프로그램의 기능을 사용할 때는 vscode 모듈을 사용해 command를 호출해 사용하는 것을 알 수 있었습니다.


추가로, Spring Boot Dashboard의 테스트 환경을 조성하기 위해 Spring Boot(Kotlin) 데모 프로젝트를 서브모듈로 추가했습니다.

수정 중인 확장 프로그램에 대한 테스트는 VSCode의 실행 및 디버그 기능을 이용해서 진행합니다.

데모 프로젝트를 서브모듈로 추가한 레포지토리

참고 자료
Spring Boot(Kotlin) 데모 프로젝트 : https://github.com/spring-guides/tut-spring-boot-kotlin
Microsoft 공식 문서 : https://code.visualstudio.com/api/get-started/your-first-extension


2. 난관

규모가 큰 여러 확장 프로그램이 얽혀있다보니 어느 부분을 살펴봐야하는지 파악하기 어려워 Java Language Server에서 컴파일 후 어떤 정보를 반환하는지에 대해 아직 파악이 안되었습니다. 해당 부분에 대해 파악이 된다면 진전이 클 것으로 예상됩니다.

두 번째 난관으로는 Spring Boot Dashboard가 Java 언어만을 고려하여 개발되었다는 점입니다. 향후에도 다른 언어를 지원할 가능성이 있기 때문에 수정 개발 시 신경을 써서 개발해야 할 것으로 보입니다.


3. 다음 목표

  1. Java Language Server에게 받는 데이터가 어떤 종류가 있는지 파악하기
  2. Kotlin Language Server 살펴보기
profile
개발자

1개의 댓글

comment-user-thumbnail
2023년 6월 9일

잘 보고갑니다.

답글 달기