@yeyelailou/co 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +73 -16
  2. package/bin//345/205/245/345/217/243.js +0 -8
  3. package/package.json +7 -6
  4. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//345/220/257/345/212/250/345/231/250.c +3 -3
  5. package//345/267/245/345/205/267//350/207/252/344/270/276/347/274/226/350/257/221/345/231/250//346/234/272/345/231/250/347/240/201/347/224/237/346/210/220/345/231/250.co +21 -1
  6. package//345/267/245/345/205/267//350/207/252/344/270/276/347/274/226/350/257/221/345/231/250//350/207/252/344/270/276/347/274/226/350/257/221.sh +73 -0
  7. package//345/267/245/345/205/267//350/207/252/344/270/276/347/274/226/350/257/221/345/231/250//350/207/252/344/270/276/351/252/214/350/257/201//347/274/226/350/257/221/351/251/261/345/212/250.co +3 -1
  8. package//345/267/245/345/205/267//350/207/252/344/270/276/347/274/226/350/257/221/345/231/250//350/207/252/344/270/276/351/252/214/350/257/201//347/274/226/350/257/221/351/252/214/350/257/201.sh +24 -8
  9. package/bin/install.js +0 -276
  10. package//345/267/245/345/205/267/lsp/server.js +0 -419
  11. package//345/267/245/345/205/267/lsp//346/265/213/350/257/225.sh +0 -81
  12. package//345/267/245/345/205/267/vscode-cocn/extension.js +0 -203
  13. package//345/267/245/345/205/267/vscode-cocn/package.json +0 -58
  14. package//345/267/245/345/205/267/vscode-cocn/syntaxes/coCN.tmLanguage.json +0 -130
  15. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/273/243/347/240/201/347/224/237/346/210/220/345/231/250.js +0 -2284
  16. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/analysis.js +0 -116
  17. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/benchmark_demo.js +0 -75
  18. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/dominance.js +0 -158
  19. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/gvn.js +0 -45
  20. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/index.js +0 -121
  21. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/ir.js +0 -237
  22. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/passes/constProp.js +0 -126
  23. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/passes/copyProp.js +0 -57
  24. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/passes/cse.js +0 -62
  25. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/passes/dce.js +0 -68
  26. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/passes/devirt.js +0 -38
  27. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/passes/escape.js +0 -67
  28. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/passes/inline.js +0 -142
  29. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/passes/loopOpt.js +0 -215
  30. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/peephole.js +0 -42
  31. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/regalloc.js +0 -212
  32. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/scheduler.js +0 -86
  33. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/spill.js +0 -78
  34. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/ssa.js +0 -235
  35. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/traceSched.js +0 -47
  36. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/unroll.js +0 -46
  37. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/harness.js +0 -33
  38. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/run_all.js +0 -11
  39. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/test_constfold.js +0 -58
  40. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/test_dce.js +0 -49
  41. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/test_e2e.js +0 -57
  42. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/test_gvn_spill.js +0 -45
  43. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/test_loop.js +0 -46
  44. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/test_regalloc.js +0 -51
  45. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/test_ssa.js +0 -65
  46. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//345/205/245/345/217/243.c +0 -9
  47. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//345/205/245/345/217/243.js +0 -38
  48. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237/AST/345/267/245/345/205/267.js +0 -126
  49. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237/index.js +0 -103
  50. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//345/206/205/350/201/224.js +0 -194
  51. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//345/207/275/346/225/260/347/211/271/345/214/226.js +0 -168
  52. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//346/243/200/346/237/245/346/266/210/351/231/244.js +0 -166
  53. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//346/265/213/350/257/225//345/206/205/350/201/224/346/265/213/350/257/225.js +0 -53
  54. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//346/265/213/350/257/225//345/207/275/346/225/260/347/211/271/345/214/226/346/265/213/350/257/225.js +0 -67
  55. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//346/265/213/350/257/225//347/253/257/345/210/260/347/253/257/346/265/213/350/257/225.js +0 -104
  56. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//346/265/213/350/257/225//347/261/273/345/236/213/346/216/250/346/226/255/346/265/213/350/257/225.js +0 -87
  57. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//346/265/213/350/257/225//350/277/220/350/241/214/346/265/213/350/257/225.js +0 -43
  58. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//346/265/213/350/257/225//351/200/203/351/200/270/345/210/206/346/236/220/346/265/213/350/257/225.js +0 -58
  59. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//347/211/271/345/214/226/347/274/223/345/255/230.js +0 -83
  60. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//347/216/257/345/242/203.js +0 -126
  61. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//347/261/273/345/236/213.js +0 -294
  62. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//347/261/273/345/236/213/346/216/250/346/226/255.js +0 -461
  63. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//350/260/203/347/224/250/345/233/276.js +0 -119
  64. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//351/200/203/351/200/270/345/210/206/346/236/220.js +0 -184
  65. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/274/226/350/257/221.sh +0 -45
  66. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/alloc.c +0 -206
  67. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/build.sh +0 -70
  68. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/dict.c +0 -143
  69. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/list.c +0 -148
  70. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/math.c +0 -129
  71. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/print.c +0 -135
  72. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/rt.h +0 -177
  73. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/string.c +0 -288
  74. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/syscall.asm +0 -153
  75. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/test.c +0 -228
  76. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266//344/270/264/346/227/266.c +0 -379
  77. package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266.c +0 -441
  78. package//345/267/245/345/205/267//350/207/252/344/270/276/347/274/226/350/257/221/345/231/250//346/267/261/345/272/246/346/257/224/350/276/203.js +0 -51
  79. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/Empty.java +0 -1
  80. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/bench.c +0 -53
  81. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/bench.co +0 -42
  82. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/bench.go +0 -43
  83. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/bench.java +0 -29
  84. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/bench.js +0 -24
  85. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/bench.py +0 -36
  86. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/bench.rs +0 -35
  87. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/empty.co +0 -0
  88. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/empty_c.c +0 -1
  89. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/empty_go.go +0 -2
  90. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/empty_rs.rs +0 -1
  91. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/346/213/274/346/216/245.c +0 -32
  92. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/346/213/274/346/216/245.co +0 -10
  93. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/346/216/222/345/272/217.c +0 -23
  94. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/346/216/222/345/272/217.co +0 -31
  95. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/346/226/220/346/263/242/351/202/243/345/245/221.c +0 -17
  96. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/346/226/220/346/263/242/351/202/243/345/245/221.co +0 -10
  97. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/346/226/220/346/263/242/351/202/243/345/245/22120.co +0 -10
  98. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/347/264/257/345/212/240.c +0 -14
  99. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/347/264/257/345/212/240.co +0 -10
  100. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200/345/257/271/346/257/224/347/273/223/346/236/234.txt +0 -164
  101. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/276/256/345/237/272/345/207/206/fib.c +0 -9
  102. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/276/256/345/237/272/345/207/206/fib.co +0 -2
  103. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/276/256/345/237/272/345/207/206/sum.c +0 -10
  104. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/276/256/345/237/272/345/207/206/sum.co +0 -3
  105. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/276/256/345/237/272/345/207/206//350/256/241/346/265/213.sh +0 -32
  106. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/276/256/345/237/272/345/207/206//350/256/241/346/265/213/347/273/223/346/236/234.txt +0 -7
  107. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//350/241/245/346/265/213.sh +0 -45
  108. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//350/256/241/346/265/213.sh +0 -163
  109. package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//350/256/241/346/265/213/347/273/223/346/236/234.txt +0 -29
@@ -1,81 +0,0 @@
1
- #!/bin/bash
2
- # coCN LSP 服务器测试脚本
3
- # 通过管道向 stdio LSP 服务器发送示例 JSON-RPC 消息,验证响应。
4
- set -e
5
-
6
- LSP_DIR="$(cd "$(dirname "$0")" && pwd)"
7
- SERVER="$LSP_DIR/server.js"
8
-
9
- echo "=== coCN LSP 服务器测试 ==="
10
- echo "服务器路径: $SERVER"
11
- echo ""
12
-
13
- # 构造一个测试 coCN 文件内容
14
- TEST_DOC='函数 加(整数 a, 整数 b) -> 整数
15
- 返回 a + b
16
- 结束
17
-
18
- 输出 加(3, 5)
19
- '
20
-
21
- # 构造 JSON-RPC 消息
22
- # 1. initialize
23
- INIT=$(printf '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"capabilities":{},"processId":%d}}' $$)
24
-
25
- # 2. initialized notification
26
- INITIALIZED='{"jsonrpc":"2.0","method":"initialized","params":{}}'
27
-
28
- # 3. didOpen
29
- DIDOPEN=$(cat <<EOF
30
- {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///tmp/test.co","languageId":"cocn","version":1,"text":$(node -e "console.log(JSON.stringify(process.argv[1]))" "$TEST_DOC")}}}
31
- EOF
32
- )
33
-
34
- # 4. definition 请求(查找 "加" 的定义;第4行 `输出 加(3, 5)`,"加" 在第3列)
35
- DEFINITION=$(cat <<EOF
36
- {"jsonrpc":"2.0","id":2,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///tmp/test.co"},"position":{"line":4,"character":3}}}
37
- EOF
38
- )
39
-
40
- # 5. hover 请求(同样悬停 "加")
41
- HOVER=$(cat <<EOF
42
- {"jsonrpc":"2.0","id":3,"method":"textDocument/hover","params":{"textDocument":{"uri":"file:///tmp/test.co"},"position":{"line":4,"character":3}}}
43
- EOF
44
- )
45
-
46
- # 6. shutdown
47
- SHUTDOWN='{"jsonrpc":"2.0","id":4,"method":"shutdown","params":null}'
48
- EXIT='{"jsonrpc":"2.0","method":"exit"}'
49
-
50
- # 打包成带 Content-Length 头的消息序列
51
- pack() {
52
- local body="$1"
53
- local len=$(printf '%s' "$body" | wc -c)
54
- printf 'Content-Length: %d\r\n\r\n%s' "$len" "$body"
55
- }
56
-
57
- INPUT=""
58
- INPUT="$INPUT$(pack "$INIT")"
59
- INPUT="$INPUT$(pack "$INITIALIZED")"
60
- INPUT="$INPUT$(pack "$DIDOPEN")"
61
- INPUT="$INPUT$(pack "$DEFINITION")"
62
- INPUT="$INPUT$(pack "$HOVER")"
63
- INPUT="$INPUT$(pack "$SHUTDOWN")"
64
- INPUT="$INPUT$(pack "$EXIT")"
65
-
66
- echo "--- 发送消息序列 ---"
67
- echo "1. initialize"
68
- echo "2. initialized"
69
- echo "3. textDocument/didOpen"
70
- echo "4. textDocument/definition (查找 加)"
71
- echo "5. textDocument/hover (悬停 加)"
72
- echo "6. shutdown + exit"
73
- echo ""
74
- echo "--- 服务器输出 ---"
75
-
76
- echo "$INPUT" | node "$SERVER" 2>/dev/null | while IFS= read -r line; do
77
- echo "$line"
78
- done
79
-
80
- echo ""
81
- echo "=== 测试完成 ==="
@@ -1,203 +0,0 @@
1
- 'use strict';
2
-
3
- const vscode = require('vscode');
4
- const path = require('path');
5
- const fs = require('fs');
6
- const { spawn } = require('child_process');
7
-
8
- let lspProcess = null;
9
- let lspConnection = null;
10
-
11
- /**
12
- * 激活扩展:启动 LSP 服务器并建立 stdio 通信
13
- * @param {vscode.ExtensionContext} context
14
- */
15
- function activate(context) {
16
- console.log('coCN 扩展已激活');
17
-
18
- // 启动 LSP 服务器
19
- startLspServer(context);
20
-
21
- // 注册命令:重新启动 LSP
22
- const restartCmd = vscode.commands.registerCommand('cocn.restartServer', () => {
23
- stopLspServer();
24
- startLspServer(context);
25
- vscode.window.showInformationMessage('coCN LSP 服务器已重启');
26
- });
27
- context.subscriptions.push(restartCmd);
28
-
29
- // 注册命令:手动诊断
30
- const checkCmd = vscode.commands.registerCommand('cocn.checkFile', () => {
31
- const editor = vscode.window.activeTextEditor;
32
- if (!editor) return;
33
- const doc = editor.document;
34
- if (doc.languageId !== 'cocn') return;
35
- // 触发 didChange 来重新诊断
36
- vscode.commands.executeCommand('cocn.restartServer');
37
- });
38
- context.subscriptions.push(checkCmd);
39
- }
40
-
41
- function startLspServer(context) {
42
- const config = vscode.workspace.getConfiguration('cocn');
43
- let serverPath = config.get('lspPath', '');
44
-
45
- // 自动查找 server.js
46
- if (!serverPath) {
47
- const candidates = [
48
- path.join(context.extensionPath, '..', 'lsp', 'server.js'),
49
- path.join(context.extensionPath, 'lsp', 'server.js'),
50
- ];
51
- for (const c of candidates) {
52
- if (fs.existsSync(c)) {
53
- serverPath = c;
54
- break;
55
- }
56
- }
57
- }
58
-
59
- if (!serverPath || !fs.existsSync(serverPath)) {
60
- vscode.window.showWarningMessage(
61
- '未找到 coCN LSP 服务器 (server.js)。请在设置中指定 cocn.lspPath。语法高亮仍可正常使用。'
62
- );
63
- return;
64
- }
65
-
66
- console.log('启动 LSP 服务器:', serverPath);
67
-
68
- lspProcess = spawn('node', [serverPath], {
69
- cwd: path.dirname(path.dirname(serverPath)), // 项目根目录
70
- stdio: ['pipe', 'pipe', 'pipe'],
71
- });
72
-
73
- lspProcess.stderr.on('data', (data) => {
74
- console.error('[LSP stderr]', data.toString());
75
- });
76
-
77
- lspProcess.on('exit', (code) => {
78
- console.log('LSP 服务器退出,代码:', code);
79
- lspProcess = null;
80
- });
81
-
82
- // 初始化
83
- sendLspRequest({
84
- jsonrpc: '2.0',
85
- id: 1,
86
- method: 'initialize',
87
- params: {
88
- processId: process.pid,
89
- rootUri: vscode.workspace.rootPath ? vscode.Uri.file(vscode.workspace.rootPath).toString() : null,
90
- capabilities: {
91
- textDocument: {
92
- synchronization: { didOpen: true, didChange: true },
93
- definition: true,
94
- hover: true,
95
- publishDiagnostics: true,
96
- },
97
- },
98
- },
99
- });
100
-
101
- // 绑定文档事件
102
- context.subscriptions.push(
103
- vscode.workspace.onDidOpenTextDocument((doc) => {
104
- if (doc.languageId !== 'cocn') return;
105
- sendLspNotification('textDocument/didOpen', {
106
- textDocument: {
107
- uri: doc.uri.toString(),
108
- languageId: doc.languageId,
109
- version: doc.version,
110
- text: doc.getText(),
111
- },
112
- });
113
- })
114
- );
115
-
116
- context.subscriptions.push(
117
- vscode.workspace.onDidChangeTextDocument((event) => {
118
- if (event.document.languageId !== 'cocn') return;
119
- sendLspNotification('textDocument/didChange', {
120
- textDocument: {
121
- uri: event.document.uri.toString(),
122
- version: event.document.version,
123
- },
124
- contentChanges: [
125
- {
126
- range: null,
127
- text: event.document.getText(),
128
- },
129
- ],
130
- });
131
- })
132
- );
133
-
134
- // 监听来自服务器的诊断(用 Buffer 按字节分帧,兼容中文)
135
- let buffer = Buffer.alloc(0);
136
- lspProcess.stdout.on('data', (data) => {
137
- buffer = Buffer.concat([buffer, data]);
138
- let idx;
139
- while ((idx = buffer.indexOf('\r\n\r\n')) !== -1) {
140
- const headerPart = buffer.slice(0, idx).toString('utf8');
141
- const m = headerPart.match(/Content-Length:\s*(\d+)/i);
142
- if (!m) {
143
- buffer = buffer.slice(idx + 4);
144
- continue;
145
- }
146
- const len = parseInt(m[1], 10);
147
- const bodyStart = idx + 4;
148
- if (buffer.length < bodyStart + len) break;
149
- const body = buffer.slice(bodyStart, bodyStart + len).toString('utf8');
150
- buffer = buffer.slice(bodyStart + len);
151
- try {
152
- const msg = JSON.parse(body);
153
- handleLspMessage(msg);
154
- } catch (e) {
155
- console.error('解析 LSP 消息失败:', e);
156
- }
157
- }
158
- });
159
- }
160
-
161
- function handleLspMessage(msg) {
162
- if (msg.method === 'textDocument/publishDiagnostics' && msg.params) {
163
- const { uri, diagnostics } = msg.params;
164
- // 转换并显示诊断
165
- const converted = (diagnostics || []).map((d) => ({
166
- severity: d.severity || 1,
167
- range: {
168
- start: { line: d.range.start.line, character: d.range.start.character },
169
- end: { line: d.range.end.line, character: d.range.end.character },
170
- },
171
- message: d.message,
172
- source: 'coCN',
173
- }));
174
- const collection = vscode.languages.createDiagnosticCollection('cocn');
175
- collection.set(vscode.Uri.parse(uri), converted);
176
- }
177
- }
178
-
179
- function sendLspRequest(req) {
180
- if (!lspProcess || !lspProcess.stdin.writable) return;
181
- const body = JSON.stringify(req);
182
- const header = `Content-Length: ${Buffer.byteLength(body)}\r\n\r\n`;
183
- lspProcess.stdin.write(header + body);
184
- }
185
-
186
- function sendLspNotification(method, params) {
187
- sendLspRequest({ jsonrpc: '2.0', method, params });
188
- }
189
-
190
- function stopLspServer() {
191
- if (lspProcess) {
192
- try {
193
- lspProcess.kill();
194
- } catch (e) {}
195
- lspProcess = null;
196
- }
197
- }
198
-
199
- function deactivate() {
200
- stopLspServer();
201
- }
202
-
203
- module.exports = { activate, deactivate };
@@ -1,58 +0,0 @@
1
- {
2
- "name": "cocn",
3
- "displayName": "coCN",
4
- "description": "coCN 中文编程语言语法高亮与语言支持",
5
- "version": "0.0.1",
6
- "publisher": "cocn",
7
- "engines": {
8
- "vscode": "^1.75.0"
9
- },
10
- "categories": [
11
- "Programming Languages"
12
- ],
13
- "activationEvents": [
14
- "onLanguage:cocn"
15
- ],
16
- "main": "./extension.js",
17
- "contributes": {
18
- "languages": [
19
- {
20
- "id": "cocn",
21
- "aliases": [
22
- "coCN",
23
- "cocn"
24
- ],
25
- "extensions": [
26
- ".co"
27
- ],
28
- "configuration": {
29
- "comments": {
30
- "lineComment": "#"
31
- }
32
- }
33
- }
34
- ],
35
- "grammars": [
36
- {
37
- "language": "cocn",
38
- "scopeName": "source.cocn",
39
- "path": "./syntaxes/coCN.tmLanguage.json"
40
- }
41
- ],
42
- "configuration": {
43
- "title": "coCN",
44
- "properties": {
45
- "cocn.lspPath": {
46
- "type": "string",
47
- "default": "",
48
- "description": "coCN LSP 服务器 server.js 的绝对路径(留空则自动从项目 lsp/ 目录查找)"
49
- },
50
- "cocn.enableDiagnostics": {
51
- "type": "boolean",
52
- "default": true,
53
- "description": "启用基于 coCN 解释器的诊断检查"
54
- }
55
- }
56
- }
57
- }
58
- }
@@ -1,130 +0,0 @@
1
- {
2
- "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3
- "name": "coCN",
4
- "scopeName": "source.cocn",
5
- "fileTypes": ["co"],
6
- "patterns": [
7
- { "include": "#comment" },
8
- { "include": "#string" },
9
- { "include": "#number" },
10
- { "include": "#keyword" },
11
- { "include": "#builtin-function" },
12
- { "include": "#type-name" },
13
- { "include": "#operator" },
14
- { "include": "#function-def" },
15
- { "include": "#identifier" }
16
- ],
17
- "repository": {
18
- "comment": {
19
- "name": "comment.line.number-sign.cocn",
20
- "match": "#.*$",
21
- "captures": {
22
- "0": { "name": "comment.line.number-sign.cocn" }
23
- }
24
- },
25
- "string": {
26
- "name": "string.quoted.double.cocn",
27
- "begin": "\"",
28
- "beginCaptures": {
29
- "0": { "name": "punctuation.definition.string.begin.cocn" }
30
- },
31
- "end": "\"",
32
- "endCaptures": {
33
- "0": { "name": "punctuation.definition.string.end.cocn" }
34
- },
35
- "patterns": [
36
- {
37
- "name": "constant.character.escape.cocn",
38
- "match": "\\\\."
39
- }
40
- ]
41
- },
42
- "number": {
43
- "patterns": [
44
- {
45
- "name": "constant.numeric.float.cocn",
46
- "match": "\\b\\d+\\.\\d+\\b"
47
- },
48
- {
49
- "name": "constant.numeric.integer.cocn",
50
- "match": "\\b\\d+\\b"
51
- }
52
- ]
53
- },
54
- "keyword": {
55
- "patterns": [
56
- {
57
- "name": "keyword.control.cocn",
58
- "match": "\\b(若|否则|当|循环|对于|从|到|步长|结束|跳出|继续|尝试|捕获|最终|抛出|并发|等待|那么|则)\\b"
59
- },
60
- {
61
- "name": "keyword.declaration.cocn",
62
- "match": "\\b(让|变量|常量|函数|返回|导入)\\b"
63
- },
64
- {
65
- "name": "keyword.conditional.cocn",
66
- "match": "\\b(如果|匹配|是|默认|于|在)\\b"
67
- },
68
- {
69
- "name": "keyword.operator.logical.cocn",
70
- "match": "\\b(且|或|非)\\b"
71
- },
72
- {
73
- "name": "constant.language.cocn",
74
- "match": "\\b(真|假)\\b"
75
- }
76
- ]
77
- },
78
- "type-name": {
79
- "name": "storage.type.cocn",
80
- "match": "\\b(整数|浮点|布尔|字符串|列表|字典)\\b"
81
- },
82
- "builtin-function": {
83
- "patterns": [
84
- {
85
- "name": "support.function.builtin.cocn",
86
- "match": "\\b(长度|转字符串|追加|截取|输出|断言|断言相等|词法分析|语法分析|运行|是数字|是操作符字符|是关键字|类型|键|值|键列表|值列表|范围)\\b"
87
- }
88
- ]
89
- },
90
- "function-def": {
91
- "patterns": [
92
- {
93
- "name": "meta.function.definition.cocn",
94
- "match": "(?<=函数\\s)[A-Za-z_\\u4e00-\\u9fff][A-Za-z0-9_\\u4e00-\\u9fff]*",
95
- "captures": {
96
- "0": { "name": "entity.name.function.cocn" }
97
- }
98
- }
99
- ]
100
- },
101
- "operator": {
102
- "patterns": [
103
- {
104
- "name": "keyword.operator.assignment.cocn",
105
- "match": "=>|->|="
106
- },
107
- {
108
- "name": "keyword.operator.arithmetic.cocn",
109
- "match": "\\+|\\-|\\*\\*|\\*|//|/|%|\\^|~|&|\\||<<|>>"
110
- },
111
- {
112
- "name": "keyword.operator.comparison.cocn",
113
- "match": "==|!=|<=|>=|<|>"
114
- },
115
- {
116
- "name": "keyword.operator.logical.symbol.cocn",
117
- "match": "&&|\\|\\||!"
118
- },
119
- {
120
- "name": "punctuation.separator.cocn",
121
- "match": "[\\(\\)\\[\\]\\{\\},;:\\.]"
122
- }
123
- ]
124
- },
125
- "identifier": {
126
- "name": "variable.other.cocn",
127
- "match": "[A-Za-z_\\u4e00-\\u9fff][A-Za-z0-9_\\u4e00-\\u9fff]*"
128
- }
129
- }
130
- }