Upgrade to Pro — share decks privately, control downloads, hide ads and more …

tree-sitter와 LSP를 이용한 Language Server 개발기

kakao
November 01, 2024

tree-sitter와 LSP를 이용한 Language Server 개발기

#LSP #tree-sitter #Rust #DevEx #DX #fluent-bit #vscode

본 발표에서는 LSP의 개념과 동작 방식, tree-sitter의 역할 및 활용 방법, 그리고 이를 fluent-bit 설정 파일에 적용하여 얻은 개선 사항을 소개합니다. 개발 과정에서 마주한 도전 과제와 그 해결 방법도 함께 공유합니다.

발표자 : vince.joe
카카오톡 메시징 시스템을 개발 및 운영하는 빈스입니다. 클라이밍과 방탈출을 좋아합니다.

kakao

November 01, 2024
Tweet

More Decks by kakao

Other Decks in Programming

Transcript

  1. #BDLHSPVOE  fl VFOU - CJUয়೑ࣗझ҃۝۽Ӓ ݫ౟ܼࣻ૘߂оҕ೐۽Ӓ۔  $/$'(SBEVBUFE1SPKFDU 

    EPDLFSQVMMরߣج౵  సݫद૚दझమীࢲ੸ӓࢎਊ઺   fl VFOU - CJU 'MVFOU#JUTVSQBTTFTCJMMJPO%PDLFSQVMMT ֙ਘੌ IUUQT  fl VFOUCJUJPCMPH fl VFOU - CJU - TVSQBTTFTCJMMJPO - EPDLFS - QVMMT
  2. @INCLUDE kakao.conf [INPUT] Name tail Path /var/log/containers/*.log Parser docker Tag

    kube.* Mem_Buf_Limit 5MB [FILTER] Name kubernetes Match kube.* [OUTPUT] Name es Match * Logstash_Format On Retry_Limit False Logstash_Prefix_Key es_index  fl VFOU - CJU਷੗୓ޙߨ੄ࢸ੿౵ੌࢎਊ  *%&ীࢲ঱য૑ਗহ਺  ঌӝয۰਍٣పੌٜ  ࢸ੿౵ੌ੘সदपࣻೞӝऔҊ ࢤ࢑ࢿبڄয૗  ѐࢶೡࣻহਸө #BDLHSPVOE
  3. #BDLHSPVOE { "name": "Java", "scopeName": "source.java", "patterns": [ { "patterns":

    [ { "match": "(?<=\\.)\\s*\\.|\\.(?=\\s*;)", "name": "invalid.illegal.character_not_allowed_here.java" }, { "match": "(?<!_)_(?=\\s*(\\.|;))|\\b\\d+|-+", "name": "invalid.illegal.character_not_allowed_here.java" }, { "match": "[A-Z]+", "name": "invalid.deprecated.package_name_not_lowercase.java" }, { "match": "(?x)\\b(?<!\\$)\n(abstract|assert|boolean| break|byte|case|catch|char|class|\nconst|continue|default|do|double|else| enum|extends|final|\nfinally|float|for|goto|if|implements|import| instanceof|int|\ninterface|long|native|new|non-sealed|package|permits| private|protected|public|\nreturn|sealed|short|static|strictfp|super| switch|syncronized|this|\nthrow|throws|transient|try|void|volatile|while| yield|\ntrue|false|null)\\b", "name": "invalid.illegal.character_not_allowed_here.java" },  4ZOUBY%F fi OJUJPO-BOHVBHFࢎਊदب  5FYU.BUFHSBNNBS  4VCMJNF4ZOUBY    য۵׮  ؊ߧਊ੸੉Ҋ ٜ݅ӝए਍ߑߨ਷হਸө  -BOHVBHF4FSWFS1SPUPDPM -41
  4. ਃ୒ ਽׹ Content-Length: 1234 { "jsonrpc": "2.0", "id": 1, "result":

    [ { "documentation": { "kind": "markdown", "value": "..." }, "insertText": "...", "insertTextFormat": 2, "insertTextMode": 2, "kind": 15, "label": "Collectd", } ... ] } Content-Length: 333 { "jsonrpc": "2.0", "id": 1, "method": "textDocument/completion", "params": { "textDocument": { "uri": "file:///vince/fluent-bit.conf" }, "position": { "line": 32, "character": 4 }, "context": { "triggerKind": 1 } } } -BOHVBHF4FSWFS1SPUPDPM -41 FYBNQMF
  5.  -41ҳഅೞחѪਵ۽୭ઙѾ੿  ؀ࠗ࠙*%&ী-BOHVBHF$MJFOUҳഅ੉غয੓਺  WTDPEF OFPWJN IFMJY  

    *OUFMMJ+ $PNNFSDJBM7FSTJPO0OMZ  -BOHVBHF4FSWFS1SPUPDPM -41  +FU#SBJOT *OUFMMJ+1MBUGPSN1MVHJO4%,-BOHVBHF4FSWFS1SPUPDPM -41  ֙ਘੌ IUUQT QMVHJOTKFUCSBJOTDPNEPDTJOUFMMJKMBOHVBHF - TFSWFS - QSPUPDPMIUNM
  6.  +BWBTDSJQU%4-ਸ੉ਊೠ.PEFSO1BSTFS(FOFSBUPS  ౠ૚  ߧਊࢿ  ࡅܰ׮  উ੿੸

     ੄ઓࢿহ਺  ٜ݅ӝԨऔ׮ 1BSTFS(FOFSBUPSUSFF - TJUUFS USFF - TJUUFSMPHP୹୊IUUQT HJUIVCDPNUSFF - TJUUFSUSFF - TJUUFSCMPCDBFDEGGGCBGDBCBEEPDTBTTFUTJNBHFTUSFF - TJUUFS - TNBMMQOH
  7.  ࢤࢿػ1BSTFSܳৈ۞঱যীࢲऔѱࢎਊоמ  ݆਷ী٣ఠо4ZOUBY)JHIMJHIUJOHਸਤ೧USFF - TJUUFSܳࢎਊ  /FPWJN &NBDT ;FE

    )FMJY   WTDPEFחѐߊ઺ *OUFMMJ+ח޷੿ 1BSTFS(FOFSBUPSUSFF - TJUUFS  (JU)VCNJDSPTPGUWTDPEF 4VQQPSUTZOUBYIJHIMJHIUJOH ֙ਘੌ IUUQT HJUIVCDPNNJDSPTPGUWTDPEFJTTVFT  :PV5SBDL 5SFF - TJUUFSDVTUPNMBOHVBHFTVQQPSU ֙ਘੌ IUUQT ZPVUSBDLKFUCSBJOTDPNJTTVF*+1-5SFF - TJUUFS - DVTUPN - MBOHVBHF - TVQQPSU
  8. &YBNQMF4PVSDF$PEFGPS$ 1BSTF5SFF 5FYUVBM3FQSFTFOUBUJPO translation_unit [0, 0] - [3, 0] function_definition

    [0, 0] - [2, 1] type: primitive_type [0, 0] - [0, 3] declarator: function_declarator [0, 4] - [0, 9] declarator: identifier [0, 4] - [0, 7] parameters: parameter_list [0, 7] - [0, 9] body: compound_statement [0, 10] - [2, 1] return_statement [1, 1] - [1, 10] number_literal [1, 8] - [1, 9] int foo() { return 1; } 1BSTFS(FOFSBUPSUSFF - TJUUFS
  9. module.exports = grammar({ name: 'fluentbit', extras: $ => [], rules:

    { config: $ => repeat( choice( $._config_block, seq($.comment, $._newline), ), ), _config_block: $ => choice( $.section, $.directive, ), section: $ => seq( field('header', $.section_header), field('body', $.section_body), ), section_header: $ => seq( '[', field('name', $.section_header_type), ']', $._newline, ), ... }, });
  10.  ѐߊ঱য -41೐ۨ੐ਕ௼ࢶ੿  ѐߊಞ੄ࢿ  ଵҊೡ৘ઁо݆਷૑  ࢲߡࢎਊद߹ب۠ఋ੐੉೙ਃೠ҃਋חߓઁ 

    ୭ઙ੸ਵ۽3VTU UPXFS - MTQ۽Ѿ੿ Ҋ۰ࢎ೦ 'FSSJTMPHP $$ ୹୊IUUQT SVTUBDFBOOFU
  11.  ৈ۞-BOHVBHF4FSWFSܳଵҊ  SVTU - BOBMZ[FS UPXFS - MTQҳഅ୓ SVCZ

    - MTQ١׮ܲҳഅ୓  ҳഅӝמࢶ੿  ੗ز৮ࢿ  ௏٘૓ױ  )PWFS ҳഅ
  12.  fl VFOU - CJUTDIFNBKTPO౵ੌҗ fl VFOU - CJU -

    EPDTഝਊೠ$PEFHFOFSBUJPO  ੗ز৮ࢿ  )PWFS  USFF - TJUUFS۽1BSTF5SFFࢤࢿ  ੗ز৮ࢿ  ௏٘૓ױ ҳഅ
  13. // https://packages.fluentbit.io/{version}/fluent-bit-schema-{version}.json { "fluent-bit": { "version": "3.1.5", "schema_version": "1", "os":

    "linux" }, "inputs": [ { "type": "input", "name": "cpu", "description": "CPU Usage", "properties": { "options": [ { "name": "pid", "description": "Configure a single process to measure usage via their PID", "default": "-1", "type": "integer" }, ] } }, //... ] }
  14. fl VFOU - CJUDPO fi H fi MF 1BSTFUSFF config

    [0, 0] - [3, 0] section [0, 0] - [3, 0] header: section_header [0, 0] - [1, 0] name: section_header_type [0, 1] - [0, 6] body: section_body [1, 0] - [3, 0] entry [1, 4] - [1, 18] key: key_type [1, 4] - [1, 8] value: value_type [1, 14] - [1, 18] entry [2, 4] - [2, 39] key: key_type [2, 4] - [2, 8] value: value_type [2, 14] - [2, 39] [INPUT] name tail path /var/log/containers/*.log USFF - TJUUFS -fl VFOUCJU
  15. // language_server.rs use tower_lsp::LanguageServer; use crate::document::TextDocument; struct Backend { map:

    Arc<RwLock<HashMap<Url, TextDocument>>>, } impl LanguageServer for Backend { async fn completion(&self, params: CompletionParams) -> JsonRpcResult<Option<CompletionResponse>> { // ... } // other methods .. }
  16. ୭੸ച  3PQF੗ܐҳઑࢎਊ  USFF - TJUUFS੄*ODSFNFOUBM1BSTFࢎਊ 0QFSBUJPO 3PQF 4USJOH

    *OEFY 0 MPHO 0  4QMJU 0 MPHO 0  *OTFSU 0 MPHO 0 O %FMFUF 0 MPHO 0 O "QQFOE 0  BNPSUJ[FE
  17.  -BOHVBHF4FSWFS1SPUPDPM  ѐߊ ٣ߡӦ੄য۰਑  65'  USFF -

    TJUUFS  CSFBLJOHDIBOHFT  ޙࢲചࠗ઒  UPXFS - MTQ  زदࢿޙઁ  ݫੋప੉ց੄ࠗ੤  fl VFOU - CJU  ࢸ੿౵ੌഛ੢੗оDPOGۄࢲ׮ܲ೐۽Ӓ۔җҀஜ ইऔѢաয۰਍੼  (JU)VCFCLBMEFSPOUPXFS - MTQ $POTJEFSEJUDIJOHDPODVSSFOUIBOEMFSFYFDVUJPO ֙ਘੌ IUUQT HJUIVCDPNFCLBMEFSPOUPXFS - MTQJTTVFT
  18.  -BOHVBHF4FSWFSIUUQT HJUIVCDPNTI - DIP fl VFOU - CJU -

    MTQ  USFF - TJUUFSIUUQT HJUIVCDPNTI - DIPUSFF - TJUUFS - fl VFOUCJU  74$PEF&YUFOTJPO  IUUQT NBSLFUQMBDFWJTVBMTUVEJPDPNJUFNT JUFN/BNFTI - DIPWTDPEF -fl VFOU - CJU  IUUQT PQFO - WTYPSHFYUFOTJPOTI - DIPWTDPEF -fl VFOU - CJU "QQFOEJY
  19. 2"